Finding a record and showing it -- how?

I’d like to prompt a user for the value of a Name field, then display
the record. Rails tells me that it cannot do a find without an ID. I
guess it must be that I’m not passing back properly the data from the
view to the controller.
Thanks for the help
joshi

The find_user.rhtml view:

Enter User Name <%= start_form_tag %>

Name: <%= text_field_tag :name, params[:name] %>

<%= submit_tag "Find", :class => "submit" %>

<%= end_form_tag %>

The find_user action in user_controller.rb

def find_user
user = User.find_by_name(params[:name])
if user
redirect_to(:controller => “user”, :action => “show”)
else
flash[:notice] = “Unable to find user name”
end
end

You are redirecting to the show action without passing on the ID you
found.
redirect_to(:controller => “user”, :action => “show”, :id => user.id)

On 6/11/06, joshi [email protected] wrote:

end end


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Jón Borgþórsson wrote:

You are redirecting to the show action without passing on the ID you
found.
redirect_to(:controller => “user”, :action => “show”, :id => user.id)

On 6/11/06, joshi [email protected] wrote:

end end


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

That fixed the problem. Thank you so much!