Skip to content

Instantly share code, notes, and snippets.

@pitosalas
Created March 5, 2020 17:04
Show Gist options
  • Save pitosalas/2167626d70f5d3ac92bf1e4806c5be37 to your computer and use it in GitHub Desktop.
Save pitosalas/2167626d70f5d3ac92bf1e4806c5be37 to your computer and use it in GitHub Desktop.
Form with hidden fields
# routes.rb
get :show_form, to: 'users#show_form'
get :do_form, to: 'users#do_form'
# added to users_controller.rb
# GET /show_form
def show_form
end
# GET /do_form
def do_form
@top_secret = params[:top_secret]
@top_top_secret = params[:top_top_secret]
respond_to do |format|
format.html
end
end
# views/users/show_form.html.erb
<%= form_with(url: "/do_form", method: "get", local:true) do %>
<%= hidden_field_tag(:top_secret, 43) %>
<%= hidden_field_tag(:top_top_secret, 42) %>
<%= submit_tag("Wanna know a secret?") %>
<% end %>
# views/users/do_form.html.erb
<h1>You're cleared</h1>
1. Top Secret: <%= @top_secret %>
1. Top Top Secret: <%= @top_top_secret %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment