开发者

Rails/Formtastic Newbie: Setting display field for referenced "select" box

New formtastic user here.

I have a relationship user has_many clients

In formtastic, if I do something such as

f.input :employer

it returns a select box of all employer object referen开发者_开发百科ces. I'd like to display (last name, first name) instead. I'm sure this is very simple, but I can't figure out exactly how to do it.. Any help appreciated.


These didnt work for me, however, this did:

<%= f.input :user, :label => "Author", :label_method => :username %> 

Also a little cleaner ^^

Or, you can set the display method once and for all on the model itself:

(In employer.rb)

def to_label
  email
end


Try

f.input :employers, :as => :select, :collection => Employer.find(:all, :order => "last_name ASC")

or

f.input :employers, :as => :select, :collection => Employer.collect {|e| [e.last_name, e.id] }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜