Hi, I am getting undefined method `map'' for #<UserJob:0x7f42671ae1a8> with the code below. I''ve looked everywhere and I don''t get what I am doing wrong Controller: @user_jobs = UserJob.find_by_user_id(current_user.id) View: <% form_remote_for(@user_project, :complete => ''editObjectDialog.close()'') do |f| %> <%= f.error_messages %> <% if @user_jobs %> <p> <%= f.label :user_job %><br /> <%= collection_select :user_project :user_job_id, @user_jobs, :id, :title %> </p> <% end %> <% end %> Thanks for your help --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 7, 9:05 pm, kojilab <koji...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am getting > undefined method `map'' for #<UserJob:0x7f42671ae1a8> > with the code below. I''ve looked everywhere and I don''t get what I am > doing wrong > > Controller: > @user_jobs = UserJob.find_by_user_id(current_user.id) >This is not an array, it''s an instance of UserJob. collection_select expects an array (and judging by the variable name so are you). Dynamic finds of the form find_by_xxx are analogous to find :first, ... whereas it looks like you want find_all_by_xxx which is like a find :all. Having said that, most people would have the appropriate associations in place so that they could just write current_user.user_jobs. Fred> View: > <% form_remote_for(@user_project, :complete => > ''editObjectDialog.close()'') do |f| %> > <%= f.error_messages %> > <% if @user_jobs %> > <p> > <%= f.label :user_job %><br /> > <%= collection_select :user_project :user_job_id, > @user_jobs, :id, :title %> > </p> > <% end %> > <% end %> > > Thanks for your help--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
kojilab wrote:> Hi, > > Controller: > @user_jobs = UserJob.find_by_user_id(current_user.id) > > View:-----> <%= collection_select :user_project :user_job_id, > @user_jobs, :id, :title %> > ---- > > Thanks for your helpI usually do this: Controller: @user_jobs_list=[] @user_jobs=UserJob.find_by_user_id(current_user.id) for users in @user_jobs @user_jobs_list << [users.name, users.id] end and then.. <%=collection select :user_project :user_job_id, @user_jobs_list, :id, :title%> Now the collection_select gets what it wants. Jay -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---