Model associations

1 view
Skip to first unread message

robbe...@gmail.com

unread,
Feb 12, 2009, 5:22:41 AM2/12/09
to Lipsiadmin
Hi,
I'm creating a small weblog and got some questions about model
associations.

Got an Article model with some standard columns. In the article.rb I
set has_many :comments
Next is a Comment model which has an article_id. In comment.rb i have
belongs_to :article

Nothing special so far..
But when I generate the lipsiadmin pages for the Comment model the
article_id column is not shown. I Would like to have a selectbox
there.

Did I forgot something? How can i do this?

Regards,

Robbert Dol, Dol Webcreations

Davide D'Agostino

unread,
Feb 12, 2009, 5:30:03 AM2/12/09
to lipsi...@googlegroups.com
Hi,

at the moment Lipsiadmin don't autocomplete association, you need to do this manually.

Is pretty pretty simple, you can in your controller add some like

        return_data[:comments] = accounts.collect { |u| { :id => u.id,
                                                          :email => u.email,
  :body => u.body,
                                                          :article => u.article.name
                                                          :created_at => u.created_at } }

Then in the .js file add:

var items = [
  {  name: 'article' },

...

  columns: [
    selections,
    {
      header: 'Article Name',
      sortable: true,
      dataIndex: 'article'
   },{
  ....

That's all!

Robbert Dol

unread,
Feb 12, 2009, 5:58:46 AM2/12/09
to Lipsiadmin
Thanks for the quick response!
It is indeed pretty simple, as i expected but just looked over it.

I also added this to my form partial:

%li
%label Article
=select :comment,:article_id, Article.find(:all).collect {|a|
[ (a.id.to_s+"-"+a.title),a.id ]},{:include_blank => false, :selected
=> @comment.article_id }


Will the associations be automated in the next version? (Hope so :-) )

Regards,

Robbert


Davide D'Agostino

unread,
Feb 12, 2009, 6:02:46 AM2/12/09
to lipsi...@googlegroups.com
Yea, but is not simple do this because, the storing value is dead
simple... 99% is the ID, but the showing value?

You use for example: (a.id.to_s+"-"+a.title), is very difficult to
predict them.



Il giorno 12/feb/09, alle ore 11:58, Robbert Dol ha scritto:

Robbert Dol

unread,
Feb 12, 2009, 7:42:27 AM2/12/09
to Lipsiadmin
Maybe let the user define it in the corresponding model or ontroller,
this is done by lots of other scaffold/admin systems..



Reply all
Reply to author
Forward
0 new messages