A problem http POST params


#1

this is my HTML:

and the form_controller:
class FormController < ApplicationController
def index
@username=params[:username]
end
end

what’s wrong about this? it works with GET method.
but the API shows that params() Returns both GET and POST \parameters
in a single hash.
there’s the error message below

ActionController::InvalidAuthenticityToken in FormController#index

ActionController::InvalidAuthenticityToken

RAILS_ROOT: /home/Learning/workspace/myapp
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
request_forgery_protection.rb:79:in verify_authenticity_token' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ callbacks.rb:178:insend’
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/
callbacks.rb:178:in evaluate_method' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ callbacks.rb:166:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
filters.rb:225:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:629:inrun_before_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
filters.rb:615:in call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:610:inperform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:inms’
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:inms’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ rescue.rb:160:inperform_action_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
flash.rb:141:in perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:523:insend’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
base.rb:523:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:606:inprocess’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
base.rb:391:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:386:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
routing/route_set.rb:433:in `call’

/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
request_forgery_protection.rb:79:in verify_authenticity_token' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ callbacks.rb:178:insend’
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/
callbacks.rb:178:in evaluate_method' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ callbacks.rb:166:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
filters.rb:225:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:629:inrun_before_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
filters.rb:615:in call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:610:inperform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:inms’
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:inms’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ rescue.rb:160:inperform_action_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
flash.rb:141:in perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:523:insend’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
base.rb:523:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:606:inprocess’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
base.rb:391:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:386:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
routing/route_set.rb:433:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ dispatcher.rb:88:indispatch’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
dispatcher.rb:111:in _call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ dispatcher.rb:82:ininitialize’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
query_cache.rb:29:in call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ query_cache.rb:29:incall’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
connection_adapters/abstract/query_cache.rb:34:in cache' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ query_cache.rb:9:incache’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
query_cache.rb:28:in call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ connection_adapters/abstract/connection_pool.rb:361:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/head.rb:9:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/methodoverride.rb:24:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
params_parser.rb:15:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ rewindable_input.rb:25:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
session/cookie_store.rb:93:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ reloader.rb:9:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
failsafe.rb:11:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/lock.rb:11:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/lock.rb:11:in synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/lock.rb:11:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
dispatcher.rb:106:in call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/urlmap.rb:46:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/urlmap.rb:40:ineach’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/urlmap.rb:40:in call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb: 17:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/content_length.rb:13:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/handler/webrick.rb:46:inservice’
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
/usr/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:instart’
/usr/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:instart’
/usr/lib/ruby/1.8/webrick/server.rb:92:in each' /usr/lib/ruby/1.8/webrick/server.rb:92:instart’
/usr/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/lib/ruby/1.8/webrick/server.rb:82:instart’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/handler/webrick.rb:13:in run' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111 /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require’
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in
`require’
script/server:3

/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
request_forgery_protection.rb:79:in verify_authenticity_token' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ callbacks.rb:178:insend’
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/
callbacks.rb:178:in evaluate_method' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ callbacks.rb:166:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
filters.rb:225:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:629:inrun_before_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
filters.rb:615:in call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:610:inperform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:inms’
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:inms’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ rescue.rb:160:inperform_action_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
flash.rb:141:in perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:523:insend’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
base.rb:523:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:606:inprocess’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
base.rb:391:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:386:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
routing/route_set.rb:433:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ dispatcher.rb:88:indispatch’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
dispatcher.rb:111:in _call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ dispatcher.rb:82:ininitialize’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
query_cache.rb:29:in call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ query_cache.rb:29:incall’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
connection_adapters/abstract/query_cache.rb:34:in cache' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ query_cache.rb:9:incache’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
query_cache.rb:28:in call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ connection_adapters/abstract/connection_pool.rb:361:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/head.rb:9:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/methodoverride.rb:24:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
params_parser.rb:15:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ rewindable_input.rb:25:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
session/cookie_store.rb:93:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ reloader.rb:9:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
failsafe.rb:11:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/lock.rb:11:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/lock.rb:11:in synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/lock.rb:11:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
dispatcher.rb:106:in call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/urlmap.rb:46:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/urlmap.rb:40:ineach’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/urlmap.rb:40:in call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb: 17:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/content_length.rb:13:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/handler/webrick.rb:46:inservice’
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
/usr/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:instart’
/usr/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:instart’
/usr/lib/ruby/1.8/webrick/server.rb:92:in each' /usr/lib/ruby/1.8/webrick/server.rb:92:instart’
/usr/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/lib/ruby/1.8/webrick/server.rb:82:instart’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/handler/webrick.rb:13:in run' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111 /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require’
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in
require' script/server:3 -e:2:inload’
-e:2

Request

Parameters:

{“username”=>“123”}

Show session dump


Response

Headers:

{“Content-Type”=>"",
“Cache-Control”=>“no-cache”}


#2

because of security …

you need to specify ‘removal’ from token protection in your controller,
eg
class FormController << ApplicationController
protect_from_forgery :only => [:create, :update, :destroy]

def index

end
end

Learning wrote:

end
RAILS_ROOT: /home/Learning/workspace/myapp
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
core_ext/benchmark.rb:17:in ms' base.rb:523:insend’

/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/
base.rb:523:in process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ query_cache.rb:9:incache’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
vendor/rack-1.0/rack/lock.rb:11:in synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ /usr/lib/ruby/1.8/webrick/server.rb:162:instart’
gem_original_require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/ benchmarking.rb:68:inperform_action_without_rescue’
flash.rb:141:in perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ query_cache.rb:29:incall’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
failsafe.rb:11:in call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ vendor/rack-1.0/rack/handler/webrick.rb:46:inservice’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
Request

Headers:

{“Content-Type”=>"",
“Cache-Control”=>“no-cache”}

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

  • experienced RoR/PHP freelancer, available for hire

www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz


#3

Does RoR has an easy way to tell different about GET and POST params
just
like $_GET and $_POST in PHP?


#4

On May 13, 6:12 am, Yongning L. removed_email_address@domain.invalid wrote:

Does RoR has an easy way to tell different about GET and POST params just
like $_GET and $_POST in PHP?

You can use the request object:

case request.method
when :get
#Do stuff for GET method
return
when :post
#Do stuff for POST method
return
end