Hello, I am quite a newbie to RoR, I hope you maybe able to help. I have a collection_select in a _form.rhtml: "collection_select(:assets, :model_id, @models, :id, :model_ref,options={:prompt => ''- Select a model -''})" As you see my drop down menu will show the model_ref column. 1) Is it possible to have more than one column. For example I would like to concatenate the "description" column after each model_ref in the drop down menu. 2) The "options={:prompt" do not give back any feedback to use. The drop down list do not give prompt. Is it obsolete ? Thanks in advance. Best --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Nov-30 04:02 UTC
Re: Collection_select with two columns and a prompt
Rhaps wrote:> Hello, > I am quite a newbie to RoR, I hope you maybe able to help. > > I have a collection_select in a _form.rhtml: > > "collection_select(:assets, :model_id, @models, :id, > :model_ref,options={:prompt => ''- Select a model -''})" > > As you see my drop down menu will show the model_ref column. > 1) Is it possible to have more than one column. For example I would > like to concatenate the "description" column after each model_ref in > the drop down menu.Yes. Create an instance method in your Model class like def model_ref_and_description model_ref + '' '' + description end and use this as the text method in your collection_select call.> 2) The "options={:prompt" do not give back any feedback to use. The > drop down list do not give prompt. > Is it obsolete ?No, when you see a parameter like "options = {}" in the rdoc API of a method, this is just showing you how the parameter is written in the definition of the method in the core code. "options" is the internal name this code uses to work with this parameter; the parameter you send in is just a hash, defaulting to the empty hash when not present. So in your call above delete the characters "options=", and just send in the hash containing the :prompt option. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Nov-30 04:51 UTC
Re: Collection_select with two columns and a prompt
Rhaps wrote:> "collection_select(:assets, :model_id, @models, :id, > :model_ref,options={:prompt => ''- Select a model -''})" > ... > 2) The "options={:prompt" do not give back any feedback to use. The > drop down list do not give prompt. > Is it obsolete ?But the real reason you''re not seeing the prompt is that it''s only included and shown if the value is blank, which means you have to define the model_id field in the assets table as default NULL. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark, Thanks a lot for the full explanation. I''ve placed def model_ref_and_description model_ref + '' '' + description end into my models controller, and changed the collection_select to this : <%= collection_select(:assets, :model_id, @models, :id, :model_ref_and_description ) %></p> But I get an : undefined method `model_ref_and_description'' I may have forget something... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Nov-30 13:46 UTC
Re: Collection_select with two columns and a prompt
Rhaps wrote:> I''ve placed > > def model_ref_and_description > model_ref + '' '' + description > end > > into my models controller, and changed the collection_select to this : > <%= collection_select(:assets, :model_id, @models, :id, > :model_ref_and_description ) %></p> > > But I get an : > undefined method `model_ref_and_description''You say you put it in your "models controller". It should go inside class Model, a class descended from ActiveRecord::Base. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Oupsss sorry I should stop working when I try to code at the same time. Thanks a lot it rocks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---