Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Hayden Taylor
5,076 PointsBuild a Simple Ruby on Rails Application - Generating the user model problems --> every time I enter a email and password it says its blank
I am working on the lesson: Generating the user model problems under section Ruby on Rails Application. I got devise working kind of... the problem is when testing out the user sign_up page when I enter in a email and password and click sign up I get the follow error message:
2 errors prohibited this user from being saved:
Email can't be blank
Password can't be blank
I don't really know how to fix this... I have tried adding some more code to application_controller.rb Here is what it looks like now:
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
protect_from_forgery
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:name, :email) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password, :password_confirmation) }
end
end
https://github.com/plataformatec/devise#strong-parameters
And still nothing.
Any help would be great,
Thanks!
7 Answers
Ricardo De la Fuente
6,782 PointsNoticed a couple of differences from what I put together, try this
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << [:email, :password] #add or remove parameters as needed
end
end
Nicolai Knoll
9,481 PointsHi, I ran into the same problem here. I'm using rails 4 and had to include the gem 'protected_attributes'.
If I'm now trying to sign up as a new user i got there error:
2 errors prohibited this user from being saved: Email can't be blank Password can't be blank
The error is shown on the page directly and not on a rails error page.
Ricardo De la Fuente: I also tried your code but still get the same error.
Hayden Taylor
5,076 PointsHey I figured it out awhile before Christmas but I cant remember for the life of me right now I will post back an answer when it comes to me hopefully within the next day haha.
Nicolai Knoll
9,481 PointsThanks Hayden, that would be great!
Ricardo De la Fuente
6,782 PointsCould you by any chance post a copy of your project or link to it's github repository thus far, it's kind of hard to debug without the reest of the code
Ricardo De la Fuente
6,782 PointsCould you by any chance post a copy of your project or link to it's github repository thus far, it's kind of hard to debug without the remaining code as it could be a number of things, in a number of files
--apologies for the duplicate reply, meant to add to the above comment which I cannot, for some reason.. edit
Nicolai Knoll
9,481 PointsThanks Ricardo. You can find the repository on fitub.
Nicolai Knoll
9,481 PointsThanks Ricardo. You can find the code on github.
Ricardo De la Fuente
6,782 PointsAlright... so here's the issue I encountered with your version of the project:
I'm guessing your first attempt to fix the issue involved adding the following line to the gemfile:
gem 'protected_attributes'
Since we're using strong parameters (the 4.0 way) with devise, you'll want to remove this gem, as well as the following line from the statuses model (status.rb):
attr_accessible :content, :name
The line above is not necessary as you've already implemented the following within the statuses controller:
def status_params
params.require(:status).permit(:name, :content)
end
P.S. Remember to (1) re-run bundle at the command line & (2) that the following line:
devise_parameter_sanitizer.for(:sign_up) << [:user_name, :last_name, :first_name]
in the application controller need only include parameters you've personally added to the user model; :email & :password were used as examples in my first post, but these two fields are already accessible to devise via it's "database authenticatable" module.
Nicolai Knoll
9,481 PointsCool, works now. Thanks!
Holly Banning
16,096 PointsHi all,
I am also having this problem but your solutions don't seem to be working for my files. Any help would be great! The files are here on git hub: https://github.com/Payge/treebook