Created
December 28, 2015 20:27
-
-
Save aalvesjr/87a24e65ba3e244c0c17 to your computer and use it in GitHub Desktop.
[RAILS] Dicas de como debugar um controller de dentro do console 'rails c'
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
# De dentro do console do rails, temos a variavel app, | |
# de onde podemos consultar a sessão ou executar get e post em rotas da nossa aplicação | |
app.get "/dashboard/index" | |
# Redirected to http://www.example.com/login | |
# Filter chain halted as :require_logged_user rendered or redirected | |
# Completed 302 Found in 20ms (ActiveRecord: 0.0ms) | |
# => 302 | |
app.session.to_hash | |
#=> {"session_id"=>"01259fd413c0c5be6aa41036c34dce20", | |
# "_csrf_token"=>"AnKSbt26UDElVJfNInE0UtuDQPVig7LonImJ8hFc9WI=", | |
# "flash"=>{"discard"=>[], "flashes"=>{"notice"=>"É necessário estar logado!"}}} | |
app.get '/login' | |
#Started GET "/login" for 127.0.0.1 at 2015-12-28 18:23:46 -0200 | |
# ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" | |
#Processing by SessionsController#new as HTML | |
# Rendered sessions/new.html.erb within layouts/application (8.1ms) | |
#Completed 200 OK in 370ms (Views: 362.6ms | ActiveRecord: 0.0ms) | |
#=> 200 | |
app.session.to_hash | |
#=> {"session_id"=>"3ee664b2bed97a4a6388774c97932a57", "_csrf_token"=>"t3oznWlssIYR6ktcqahnGN+FdusrlYBvMdGk16iiNys="} | |
app.post "/login", {"utf8"=>"✓", "authenticity_token"=>"<copiar o _csrf_token da sessão>", login: 'login', password: 'pass'} | |
#Completed 302 Found in 48ms (ActiveRecord: 2.7ms) | |
#=> 302 | |
app.session.to_hash | |
#=> {"session_id"=>"a61adca0a18b0f59d277a0ff718b1921", "user_id"=>1, "flash"=>{"discard"=>[], "flashes"=>{"alert"=>"Logado com sucesso!"}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment