I wanna do something like this in rails
Here is what I have so far in rails:
But then I get this error:
undefined method `merge' for "test":String
How can I pass values in my hidden_field in rails?
I wanna do something like this in rails
Here is what I have so far in rails:
But then I get this error:
undefined method `merge' for "test":String
How can I pass values in my hidden_field in rails?
You should do:
"test" %>
hidden_field
expects a hash as a second argument
You are using a hidden_field instead of a hidden_field_tag. Because you are using the non-_tag version, it is assumed that your controller has already set the value for that attribute on the object that backs the form. For example:
controller:
def new ... @order.service = "test" ... end
view:
It works fine in Ruby 1.9 & rails 4
A version with the new syntax for hashes in ruby 1.9:
This also works in Rails 3.2.12:
"test" %>
By the way, I don't use hidden fields to send data from server to browser. Data attributes are awesome. You can do
'test' do |f| %>
And then get attribute value with jquery
$('form').data('service')