Francisco Calix
Francisco Calix

Reputation: 11

How to send a parameter from hidden field in rails 5?

I am setting my form like this:<%= hidden_field :room_name, @room.name %>

in my View I am getting the parameter as

room_name: !ruby/object:ActionController::Parameters parameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess Standard Apartment: ''

I just want to get the Standard Apartment Value

Upvotes: 1

Views: 3347

Answers (2)

fool-dev
fool-dev

Reputation: 7777

If you declared a form with object like

<%= form_for(@room, html: {role: "form"}) do |f| %>

here f is a form object then input field with value will look like this

<%= f.hidden_field :room_name, value: @room.name %>

the output HTML is something like this

<input value="Room Name" type="hidden" name="room[room_name]" id="room_room_name">

If your form declared without object then it will be

<%= hidden_field_tag :room_name, value: @room.name %>

Hope it will help other SO user in the future.

Upvotes: 1

Francisco Calix
Francisco Calix

Reputation: 11

I figured it out changing my form to this

<%= hidden_field_tag "room_name",@room.name %>

Upvotes: 0

Related Questions