Hi everybody,
Maybe this is a sort of newbie question but I''ve been trying to solve
it for several days without a solution.
Basically what I want to do is to pass a collection from the view to
my controller. I paste here the relevant part of both.
Controller:
@member=Member.find(:all)
if params[:new_member]=nil
@list=[]
@list.push(Member.new)
else
@list=params[''list'']
@list.push(Member.find(params[:new_member]))
end
View:
Inside a form that redirects to the controller
<select name="new_member">
<%@member.each do |member|%>
<option value="<%=member.id%>"
><%=member.name></option>
<%end%>
</select>
<%=submit_tag("Add")%>
<%= hidden_field "list", @list %> # [1]
[1] Here''s the problem. The error I got is
"undefined method `push'' for {"#<User:
0xb7086210>"=>""}:HashWithIndifferentAccess"
But more important in parameters[error log]:
""list"=>{"#<User:0xb7086210>"=>""}}"
It means that the params[''list''] value is taken as @list.name
[that is
just garbage]
I Hope someone can help me! Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
First, the comparison between params[:new_member] and nil should use
"=="
if nil == params[:new_member]
On Mar 26, 1:20 pm, Hiro
<hiromoto.hiro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi everybody,
>
> Maybe this is a sort of newbie question but I''ve been trying to
solve
> it for several days without a solution.
>
> Basically what I want to do is to pass a collection from the view to
> my controller. I paste here the relevant part of both.
>
> Controller:
>
> @member=Member.find(:all)
>
> if params[:new_member]=nil
> @list=[]
> @list.push(Member.new)
> else
> @list=params[''list'']
> @list.push(Member.find(params[:new_member]))
> end
>
> View:
>
> Inside a form that redirects to the controller
>
> <select name="new_member">
> <%...@member.each do |member|%>
> <option value="<%=member.id%>"
><%=member.name></option>
> <%end%>
> </select>
>
> <%=submit_tag("Add")%>
>
> <%= hidden_field "list", @list %> # [1]
>
> [1] Here''s the problem. The error I got is
>
> "undefined method `push'' for {"#<User:
> 0xb7086210>"=>""}:HashWithIndifferentAccess"
>
> But more important in parameters[error log]:
>
>
""list"=>{"#<User:0xb7086210>"=>""}}"
>
> It means that the params[''list''] value is taken as
@list.name [that is
> just garbage]
>
> I Hope someone can help me! Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On Mar 27, 8:53 am, Phillip <p...@phillip harris.com> wrote:> First, the comparison between params[:new_member] and nil should use > "==" > if nil == params[:new_member]Yes you''re right It was a typing error here in the post. But I still have this problem I hope so can help me. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Have a look in the log to see what the parameters are, particularly params[:list]. I think your code is assuming it is an array but the error suggests otherwise. Also have a look in the debugger to what is what. Also the source of the web page may be informative. 2009/3/27 Hiro <hiromoto.hiroshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > > > On Mar 27, 8:53 am, Phillip <p...@phillip harris.com> wrote: > > First, the comparison between params[:new_member] and nil should use > > "==" > > if nil == params[:new_member] > > Yes you''re right It was a typing error here in the post. But I still > have this problem I hope so can help me. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---