Sending parameters to controller using link_to but getting the variable name itself.

Hi,

I’m not using any form in this web page. I only have labels, text boxes and links with parameters.
The text_field code is

<%= label_tag("Member code") %> <%= text_field_tag :member_code, nil, class: 'form-control' %>

``

The link_to code is

<%= link_to “Joint and Personal loan (Ajax not implemented)”, jlpl_prints_path(member_code: ‘member_code’), :class => “btn btn-danger”, method: :post %>

``

in the controller I printed member_code to verify whats the value I’m getting.
member_code = params[:member_code]
puts"***********Inside controller member_code received is #{member_code} **************"

``

The thing is its printing the output in the console as
__Inside controller member_code received is member_code****__Why is that? I’ve filled text_field with value 180 but I’m getting the variable itself but not the value of it. Is form_tag is necessary to get this to work?

Thank you.

Hi,

How else can I send member_code to controller ?

What I meant in my first post is, I want to send member_code to controller, But when I check the value of member_code variable in the controller, it doesn’t contain any value but the variable itself. As I told before, I’ve filled my text_field with the member code of 180. When I print member_code in controller I should get 180 right? But I’m getting member_code itself. The output should be

Inside controller member_code received is 180******

Hi,

I missed the last part of your question, yeah it must be inside a form

tag. You can’t tell browser to pass a random text box value without it

being inside a form tag or through javascript.

What you’re doing now is just passing member_code value to

member_code parameter through query string

(/path?member_code=member_code), completely ignoring the text box.

Hello nanaya need some more help. In this web page I’ve member_code text_field and that value (membercode) has to be passed to different controllers which is done by more than one link_to helpers. Hence I can’t provide a single url_option to form_tag. So I googled “form_tag without action” and found a way to write it.
<%= form_tag “#” do %>
<%= link_to “joint_loan”, joint_loan_path(member_code: membercode), method: :post %>
<%= link_to “payment_detail”, … %>
<%= link_to "… %>
<% end %>

``

But still I’m not able to get the value of member_code.

Thank you.

Hi,

Hi,

I’m not using any form in this web page. I only have labels, text boxes and links with parameters.
The text_field code is
`


<%= label_tag(“Member code”) %>
<%= text_field_tag :member_code, nil, class: ‘form-control’ %>
`

The link_to code is

<%= link_to "Joint and Personal loan (Ajax not implemented)", jlpl_prints_path(member_code: 'member_code'), :class => "btn btn-danger", method: :post %>

You want to remove the quotes from the value:

member_code: 'member_code'

and just have:

member_code: member_code

However, you will have a form in your page due to the use of method: :post in your link_to; it’s just a generated form.

As others have said, you’ll need to do some Javascript (perhaps with a library like jQuery) to get the value of a field at the time the link is clicked without using a form.

-Rob