blackangel6291-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-16 10:58 UTC
Problem retrieving user id
I have a problem, I use a find.params[:id] to display a user from a list, and then I want to edit that information. I have a separate action for the edit, named change_user_details, and I retrieve the user id the same way I do for the audit_user with find.params[:id]. The problem is that the action change_user_details does not want to retrieve the current viewed user id. It gives the error Couldn''t find User without an ID. Here is the code of the two actions and the two forms. def audit_user @user = User.find(params[:id]) end def change_user_details @user = User.find(params[:id]) end <h4>Username: <%= @user.username %><h4> <h4>Email: <%= @user.email %><h4> <h4>IP: <%= @user.user_ip %><h4> <h4>First Name: <%= @user.firstname %><h4> <h4>Last Name: <%= @user.lastname %><h4> <%= link_to(''Change'', :action => ''change_user_details'') %> | <%= link_to(''Back'', :action => ''list_users'') %> <h1>Editing User Information</h1> <% form_tag :action => ''update_user'', :id => @user do %> <p><label for="user_firstname">Firstname</label><br/> <%= text_field ''user'', ''firstname'' %></p> <p><label for="user_lastname">Last Name</label><br/> <%= text_field ''user'', ''lastname'' %></p> <p><label for="user_email">Email</label><br/> <%= text_field ''user'', ''email'' %></p> <%= submit_tag("Update")%> <% end %> <%= link_to(''Back'', :action => ''audit_user'') %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Perhaps you can take a look at activescaffold... CCH http://cch4rails.blogspot.com On Oct 16, 6:58 pm, "blackangel6...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <blackangel6...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a problem, I use a find.params[:id] to display a user from a > list, and then I want to edit that information. I have a separate > action for the edit, named change_user_details, and I retrieve the > user id the same way I do for the audit_user with find.params[:id]. > The problem is that the action change_user_details does not want to > retrieve the current viewed user id. It gives the error Couldn''t find > User without an ID. > Here is the code of the two actions and the two forms. > > def audit_user > @user = User.find(params[:id]) > end > > def change_user_details > @user = User.find(params[:id]) > end > > <h4>Username: <%= @user.username %><h4> > <h4>Email: <%= @user.email %><h4> > <h4>IP: <%= @user.user_ip %><h4> > <h4>First Name: <%= @user.firstname %><h4> > <h4>Last Name: <%= @user.lastname %><h4> > > <%= link_to(''Change'', :action => ''change_user_details'') %> > | > <%= link_to(''Back'', :action => ''list_users'') %> > > <h1>Editing User Information</h1> > > <% form_tag :action => ''update_user'', :id => @user do %> > > <p><label for="user_firstname">Firstname</label><br/> > <%= text_field ''user'', ''firstname'' %></p> > > <p><label for="user_lastname">Last Name</label><br/> > <%= text_field ''user'', ''lastname'' %></p> > > <p><label for="user_email">Email</label><br/> > <%= text_field ''user'', ''email'' %></p> > > <%= submit_tag("Update")%> > > <% end %> > > <%= link_to(''Back'', :action => ''audit_user'') %>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, took care of the problem :) --~--~---------~--~----~------------~-------~--~----~ 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 10/16/07, blackangel6291-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <blackangel6291-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a problem, I use a find.params[:id] to display a user from a > list, and then I want to edit that information. I have a separate > action for the edit, named change_user_details, and I retrieve the > user id the same way I do for the audit_user with find.params[:id]. > The problem is that the action change_user_details does not want to > retrieve the current viewed user id. It gives the error Couldn''t find > User without an ID.Right, because params[:id] is empty.> Here is the code of the two actions and the two forms. > > def audit_user > @user = User.find(params[:id]) > end > > def change_user_details > @user = User.find(params[:id]) > end > > > > <h4>Username: <%= @user.username %><h4> > <h4>Email: <%= @user.email %><h4> > <h4>IP: <%= @user.user_ip %><h4> > <h4>First Name: <%= @user.firstname %><h4> > <h4>Last Name: <%= @user.lastname %><h4> > > <%= link_to(''Change'', :action => ''change_user_details'') %>This doesn''t pass an id. You need to explicitly pass it: <%= link_to ''Change'', :action => ''change_user_details'', :id => @user %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yep, it worked. Before that I used a newly created session to track the id. But it worked. Thanks a lot. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---