Hi All, I''m working on building an app that can log and edit phone call information. I''ve got the creating and editing parting working great, and I''ve started an attempt to add searching. I can''t seem to figure out how to get an [:id] parameter from a form and passed between two controller methods. Right now I have a web page with a single text field in it and a button. I want to be able to type in a valid record ID into the text field, hit the button and be taken to the edit page for the record with that ID. I realize this should be dead simple, but I haven''t figured out a way to get it to work. I keep getting an error: "Unable to find without an ID. Hopefully someone here can tell me where I''ve gone astray. Here is the code I have right now: ##controller.rb def edit @support_call = SupportCall.find(params[:id]) end def find end ##find.rhtml <html> <body> <%= start_form_tag :action => "edit", :id => params[:id] %> <%= text_field "support_call", "id" %> <%= submit_tag "Find It!" %> <%= end_form_tag %> </body> </html> -- Posted via http://www.ruby-forum.com/.
Rob Biedenharn
2006-Jun-30 18:56 UTC
[Rails] Serious noob question. Any help would be great
On Jun 30, 2006, at 2:36 PM, ds_10 wrote:> Hi All, > > I''m working on building an app that can log and edit phone call > information. I''ve got the creating and editing parting working great, > and I''ve started an attempt to add searching. I can''t seem to figure > out how to get an [:id] parameter from a form and passed between two > controller methods. Right now I have a web page with a single text > field in it and a button. I want to be able to type in a valid record > ID into the text field, hit the button and be taken to the edit > page for > the record with that ID. I realize this should be dead simple, but I > haven''t figured out a way to get it to work. I keep getting an error: > "Unable to find without an ID. Hopefully someone here can tell me > where > I''ve gone astray. Here is the code I have right now: > > > ##controller.rb > def edit > @support_call = SupportCall.find(params[:id]) > end > > def find@support_call = SupportCall.new> end > > > ##find.rhtml > <html> > <body> > > <%= start_form_tag :action => "edit", :id => params[:id] %> > > <%= text_field "support_call", "id" %> > <%= submit_tag "Find It!" %> > <%= end_form_tag %> > > </body> > </html>Your text_field helper is trying to give the form an initial value from @support_call.id The SupportCall.new just gives you an in-memory object of your model. If you can''t create them first, then you won''t ever be able to find them ;-) -Rob
ds_10 wrote:> ##controller.rb > def edit > @support_call = SupportCall.find(params[:id]) > end > > def find > end > > > ##find.rhtml > <html> > <body> > > <%= start_form_tag :action => "edit", :id => params[:id] %> > > <%= text_field "support_call", "id" %> > <%= submit_tag "Find It!" %> > <%= end_form_tag %> > > </body> > </html> >def edit @support_call = SupportCall.find(params[:support_call][:id]) end
Brian Chamberlain
2006-Jun-30 19:09 UTC
[Rails] Serious noob question. Any help would be great
yeah, and I''m not sure you need this> <%= start_form_tag :action => "edit", :id => params[:id] %>You can use this <%= start_form_tag :action => "edit"%> When the user clicks the button the browser will automatically wrap up any forms you have and post them back to the action you''ve defined. (In this case "edit") In the edit action in your controller you can pull out the data from this form like params[:support_call][:id] As the previous email illustrates. -Brian On 6/30/06, Phillip Kast <phil@unimedia.org> wrote:> > ds_10 wrote: > > ##controller.rb > > def edit > > @support_call = SupportCall.find(params[:id]) > > end > > > > def find > > end > > > > > > ##find.rhtml > > <html> > > <body> > > > > <%= start_form_tag :action => "edit", :id => params[:id] %> > > > > <%= text_field "support_call", "id" %> > > <%= submit_tag "Find It!" %> > > <%= end_form_tag %> > > > > </body> > > </html> > > > def edit > @support_call = SupportCall.find(params[:support_call][:id]) > end > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060630/bd616877/attachment.html
Wow! You guys were really fast!. Thanks everybody. Your suggestions got everything working correctly. It''s great to know that a helpful community like this is available. I''ll try to have a more challenging problem next time I need help :-) Thanks again, Dan -- Posted via http://www.ruby-forum.com/.