开发者

ROR 3 Michael Hartl tutorial - assign Admin role invalidates the user

I am experiencing an issue as I am following Michael Hartl's tutorial and currently at the end of Chapter 10.

When I use toggle in the rails console to flip the admin property of a user from false to true (I'm trying to create an Admin user), I am successful in doing so; however that user becomes invalid - when I try to log in to the application with this user's credential I am getting an error that the credentials are incorrect (even though they are)

Just from checking the logs and the lookin开发者_运维技巧g at the terminal, it seems the authenticity token is either missing or incorrect - any ideas what I am doing wrong here?

I tried following the tutorial as close as possible, I doubt I missed something, but its obviously possible.


I have had a similar problem as well. It appears (and perhaps someone else can explain why) that when you run user.toggle!(:admin), it resets the password to ''. To fix it I just ran user.update_attributes(:password => "yourpassword", :password_confirmation => 'yourpassword in the console.


Yes. I too stumbled here. Part of what made this puzzling to me as a newcomer to rails was that the error was in my understanding of how the testing sqlite db is handled, not the code that was written. I thought I was guaranteed a fresh start (new copy of project_root/db/test.sqlite3) each time testing began, but this is not always the case. More here:

Rails 3 Tutorial Chapter 11 "Validation failed: Email has already been taken" error

and here:

RailsTutorial - chapter 8.4.3 - Test database not clearing after adding user in integration test

and here:

http://rubygems.org/gems/database_cleaner (click on 'Documentation')

Most of these discussions surrounds the testing db, but the exchange also clued me in to the existence of development and production databases as well. Look at your directory listing for project_root/db for your ah-ha! moment.

hth,

Perry


I got it to work, but I still don't understand how it comes about and whether its by design or not. But, I did manage to register an Admin user, my mistake was that I didn't set the password field in the console before calling user.toggle!(:admin).
i.e.

u = User.find_by_id(1)
u.password = "password"
u.toggle!(:admin)

and it worked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜