Please help - I have couple of doubts

Hello,

I have following doubts and have spent many days trying to crack them
without luck, please help :

  1. I have a form with pure text fields at the top and a table with
    multiple rows with data derived from many objets of a class below that.
    I want to provide a link in each row which takes me to a new form. I
    can pass the id of each row via the link_to tag and read the value
    successfully in the next form.

But how do I include the value of the text boxes in each row ?

  1. Can I send an object with several attibutes in the link-to tag, say
    the object name is ‘book’, then how do i read it as an object in the
    next form, params[:book] didnot work.

  2. Is there a way to send a hash via the link_to tag ?

Thanks

atul

On Dec 27, 2007, at 6:29 AM, Atul G. wrote:

can pass the id of each row via the link_to tag and read the value
Thanks

atul

I have a somewhat similar situation in which I have a list of
“headers”. For example’s sake, lets call it a list of people and the
header includes a name and a date of birth. When the header is
clicked, I display a form that is populated with details about the
person. I do this with a variation of link_to_remote. Basically,
you make an AJAX call to the server passing the id of the object you
want to operate on. The controller action then gathers all the data
necessary and renders a partial, which is displayed in the area you
want it. If you use link_to_remote “properly”, then one of the
parameters is :update => “dom_id_of_element_to_update” and all you
have to do in the controller is a render :partial. I, however, being
the renegade (or idiot, as the case may be) that I am, call a
Javascript function which makes the AJAX call and the controller uses
render :update to refresh the element. [Ooh, I can hear all the boos
now. :)]

That should get you going. If not, feel free to ask more.

Peace,
Phillip

Thanks for a solution Phillip, anyway, is there a way to include more
than one value in the link_to tag ?

atul

Hi Phillip K.,

Thanks a lot, that solved my problem.

atul

On Dec 27, 2007, at 8:19 AM, Atul G. wrote:

Thanks for a solution Phillip, anyway, is there a way to include more
than one value in the link_to tag ?

Well, you can do basically the same thing with link_to as you do with
redirect_to, and that is

<%= link_to “My link”, :controller => ‘my_controller’, :action =>
‘my_action’, :id => 1, :my_param_1 => ‘good-bye’, :my_param_2 =>
‘cruel world!’ %>

and that will result in a url like

http://localhost:3000/my_controller/my_action/1?my_param_1=good-
bye&my_param_2=cruel+world%21

If you don’t like fat URLs, the other option is to use :method
=> :post, which I think you can do with link_to. I’ll leave
figuring that part out to you :slight_smile:

Peace,
Phillip

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