Reputation: 15
I am trying to access the requests parameters submitted over the form in a view and iterate over the hash values.
My definition in a view:
def show
@final =final_params
end
My Request parameters:
def final_params
params.permit(:Name, :Address, :MobileNumber, :"City")
end
My view:
<%= @final.each { |key, value| puts "#{key} #{value}" } %>
In my Show view it gives an empty array: enter image description here
Using console I see the data in forms data section:
.utf8: ✓
authenticity_token: Lxkt/WUyAqFvlLXcP7YsQY3PjhQ9yJFosByJwAfYRyoZseC4gaZj4J8cC4EJs/LLGBIMypbggpajmtCH3um2dA==
final[Name]: Test
final[Address]: Hyd
final[MobileNumber]: 8456213254
final[City]: Del
commit: Submit
Upvotes: 0
Views: 243
Reputation: 11186
Get rid of puts
in your view, it's not needed.
<% @final.keys.each do |key| %>
key: <%= key %> <br/>
value: <%= @final[key] %>
<% end %>
Or you can probably just do
<%= @final.inspect %>
If that's still empty then no params are being passed to your controller action. To sure add this in your controller and look at the logs:
def show
@final = final_params
puts "Final Params are set to: #{@final.inspect}" # or logger debug if puts doesn't output anything to your log
logger.debug "Final Params are set to: #{@final.inspect}"
@final
end
Upvotes: 1