i think you need the :with => '#{brand}' option.
<%= link_to_remote "Check if it is available", :update => 'avail', :url => 'check_brand', :with => '#{brand.id}' %>
i think you need the :with => '#{brand}' option.
<%= link_to_remote "Check if it is available", :update => 'avail', :url => 'check_brand', :with => '#{brand.id}' %>
or :with => 'brand = #{brand.id}'
then you can check for params[:brand] in your controller.
Put the input into a form. Then either submit the form with form_remote_tag etc, or...
Jake Parsell wrote:
i think you need the :with => '#{brand}' option.
<%= link_to_remote "Check if it is available", :update => 'avail', :url => 'check_brand', :with => '#{brand.id}' %>
The target of :with is a JavaScript string that will insert into the link's parameter list. The above won't work for a list of reasons. (Sorry, Jake, but the newbs need the list, to learn what to avoid!)
Ruby won't interpret single-quoted strings '#{}' as anything but strings containing literal hatches, braces, etc. That needed double quotes "" to invoke the sting #{embedding} system.
Next, if brand.id existed, it would resolve at Ruby time, not at Ajax time, after a user changes the field.
There might be some way to with=> a JavaScript string that fetches the field value into a named parameter, but I would just go with with => 'Form.serialize("my_form_id")'.
Aaaaand...
Jake Parsell wrote:
or :with => 'brand = #{brand.id}'
That becomes an URI query segment, so the = can't have spaces around it!
Rm Rm wrote:
<%= link_to_remote 'check' , :update => 'avail', :url => {:action => 'check_brand'} , :with =>"'brand=try'" %>
This works with the hardcoded value of try. But how do I put the value of field 'brand'.
Did you read my first post?
Rm Rm wrote:
The field is in a form but I don't need to submit the form now. Just check availability and go ahead with the rest of the form.
I haven't seen the controller / view code you're using to render the form but, based on what you've posted, I assume you're iterating through a collection of records and rendering a table row for each one using something like
@brands.each do |brand| ... end
If that's the case, then in the view code you'd use ...
<%= link_to_remote("Check if it is available", :url => {:action => 'check_brand', :id => brand.id}, :update => 'avail') %>
and in the check_brand action you'll need to change to
brand = params[:id]
Note that this will get you to the point where the code in the controller gets executed.
However, the update in the browser will not happen correctly if my assumption above about iterating through a collection is correct, given the code you've shown so far. DOM elements have to have unique IDs. It looks to me like each row in your table is going to have a <td> with an id='avail'.
Another source of potential difficulty will be your use of tables for layout. I think the <td> can be updated, but can't remember for sure. I've quit using tables because of all the hacks and workarounds needed to use them with ajax.
hth, Bill
Rm Rm wrote:
231: 232: <%= link_to_remote 'check' , 233: :update => 'avail', 234: :url => {:action => 'check_brand' }
:with => 'Form.serialize("my_form")'
236: %>
That won't submit the form, it will pass all its field values to your action.
Rm Rm wrote:
I don't want form to be submited, I just want to get the value of field 'brand' in action to validate it.
> :with => 'Form.serialize("my_form")'
> That won't submit the form, it will pass all its field values to your > action.
Do you see where I wrote "That won't submit the form"?
Rm Rm wrote:
I am not going through a loop , so update is not a problem. But I am getting errorr brand not found .
I need to see the controller code you're using to 'feed' the initial form build to help further. Two other things. 1) The view code that constructs the form. You say this is all happening within a form, but the view code you posted earlier had no form or submit tags. 2) The name of the person with whom I'm conversing.
Best regards, Bill