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

Ruby

Build 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

Noticed 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

Hi, 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.

Hey 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.

Thanks Hayden, that would be great!

Could 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

Could 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

Thanks Ricardo. You can find the repository on fitub.

Thanks Ricardo. You can find the code on github.

Alright... 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.

Cool, works now. Thanks!

Hi 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