Created
January 18, 2013 09:22
-
-
Save nnabeyang/4563389 to your computer and use it in GitHub Desktop.
rails(3.2)でformを通してpost送信されたとき、paramsの中身がどのようになっているか調べるためのスクリプトです。このスクリプトははじめに
rails new form_test
としたことが前提になっています。(すでにrailsの環境が整っている場合は"rails new {{project_name}} --skip-bundle"とした方が速い)
This file contains hidden or 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
| #path: project_name//app/controllers/home_controllers.rb | |
| class HomeController < ActionController::Base | |
| def index | |
| end | |
| def update | |
| @params = params | |
| render '/home/params' | |
| end | |
| end |
This file contains hidden or 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
| <h2>Form Test</h2> | |
| <%# path: project_name/app/views/home/index.html.erb %> | |
| <%= form_tag "/home/update", :method => :post do %> | |
| <%(0..3).each do %> | |
| <%= number_field_tag "ids[]" %> <br/> | |
| <% end %> | |
| <%= submit_tag %> | |
| <% end %> |
This file contains hidden or 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
| <pre> | |
| <%# path: project_name/app/views/home/params.html.erb %> | |
| <%= @params %> | |
| </pre> |
This file contains hidden or 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
| # path: project_name/config/routes.rb | |
| FormTest::Application.routes.draw do | |
| root :to => "home#index" | |
| match "home/update" => "home#update", :via => :post | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment