开发者

How to set session variables with app.get() in Ruby on Rails console?

How can I manually set session while calling app.get() in script/console?

For example I want to access an authorised page, but it alw开发者_StackOverflow中文版ays redirects me to sign-in page. How can I set the session before calling app.get() so that I can make an authorised call to that page?


depends on what you are using for session authentication. if you do app.class, you will see that app is an ActionController::Integration::Session. What you need to do is authenticate yourself, then hitting your restricted pages should work


Here is an ugly workaround that I did.

#Type in script/console
include ActionController::TestProcess
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller = SomeController.new
get 'action', {}, {:signed => 42} #action, params, session
#now @response has the updated response object.

Before doing another get()/post() etc make sure you reset @controller by calling @controller = SomeController.new, or else @response doesn't seem to get updated on subsequent requests.


The session is readable (http://tektastic.com/2006/12/ruby-on-rails-how-to-load-session.html) if you pull the temp file in, but unless you're using debugger, then no the session hash is not stored in a way that it can be modified from the console.


http://guides.rubyonrails.org/testing.html

This will help u..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜