Created
March 5, 2020 17:04
-
-
Save pitosalas/2167626d70f5d3ac92bf1e4806c5be37 to your computer and use it in GitHub Desktop.
Form with hidden fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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