Forum: Ruby on Rails Finding a record and showing it -- how?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42721739f52c84c12ae11ff8d9fa5966?d=identicon&s=25 joshi (Guest)
on 2006-06-11 19:47
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:

<div class="find-name-form">
  <fieldset>
    <legend>Enter User Name</legend>
    <%= start_form_tag %>
      <p>
        <label for="name">Name:</label>
        <%= text_field_tag :name, params[:name] %>
      </p>
      <p>
        <%= submit_tag "Find", :class => "submit" %>
      </p>
    <%= end_form_tag %>
  </fieldset>
</div>

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
30ee518e6fdc5b07e060775b5a542bdb?d=identicon&s=25 Jón Borgþórsson (jongretar)
on 2006-06-11 20:03
(Received via mailing list)
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 <eval_uator@hotmail.com> wrote:
>   <fieldset>
>   </fieldset>
>   end
> end
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
42721739f52c84c12ae11ff8d9fa5966?d=identicon&s=25 joshi (Guest)
on 2006-06-12 05:58
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 <eval_uator@hotmail.com> wrote:
>>   <fieldset>
>>   </fieldset>
>>   end
>> end
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --


That fixed the problem. Thank you so much!
This topic is locked and can not be replied to.