-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails 4: Role.find_or_create_by_name in db/seeds.rb #40
Comments
Your suggestion cleared my "Could not find table 'name'" error, however now I am stuck getting a unknown attribute: without_protection error. Any suggestions? Rails noob here! Setup: |
Hi @kirstywilliams! Technically it is "rails3" so it might have been better to try this running against Rails 3. Is that possible for you at this point? If not, I'll try and help you through this. Could you paste the full error you're getting? It's hard to guess what's happening without a bit more context. Pete |
Thank you for your reply. I got it to work with Rails 4.0. I didn't include the attr_accessible suggested instead opting for Rails 4.0 strong parameters this is what caused my problem. I have since included the protected attributes gem along with the attr_accessible and all is good :) Kirsty |
Kirsten if you are new it's probably better to skip using the protected attributes gem and protect against mass assignment using the rails 4 way. It's my favorite thing about rails 4. To see how it works just look at the user controller code on a new rails 4 app when you do rails g scaffold user name email password. The protection happens a before action filter defined at the bottom of the file. Good luck! |
This was my solution. |
The example seed file suggested fails under Rails 4 RC1 with the following error and a stack trace:
I converted:
to:
Now it seems to work great.
Note that I did switch from find_or_create to first_or_create, which seemed more explicit for this context.
The text was updated successfully, but these errors were encountered: