Serious noob question. Any help would be great

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

<%= start_form_tag :action => “edit”, :id => params[:id] %>

<%= text_field “support_call”, “id” %>
<%= submit_tag “Find It!” %>
<%= end_form_tag %>

On Jun 30, 2006, at 2:36 PM, ds_10 wrote:

the record with that ID. I realize this should be dead simple, but I

def find
@support_call = SupportCall.new
<%= submit_tag “Find It!” %>
<%= end_form_tag %>

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 :wink:

-Rob

ds_10 wrote:

def edit
@support_call = SupportCall.find(params[:support_call][:id])
end

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 :slight_smile:

Thanks again,

Dan

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs