简体   繁体   中英

Devise create guest records/user results in email can't be blank

I am currently trying to add guest users/records to my application and am encountering having some difficulty getting devise to play along. I am trying to follow the tutorial at http://railscasts.com/episodes/393-guest-user-record , but am stuck when it comes to bypassing the devise validation for the email, password, and username if the user is a guest. In the video tutorial at about 5:40 he quickly mentions devise but i am lost as to how to implement this change. Thanks for the help.

Update** Here is my code. Thanks for the help guys.

Here is my create action under my users_controller.rb

def create  
  @user = params[:user] ? User.new(params[:user]) : User.new_guest  
    if @user.save  
      current_user.move_to(@user) if current_user && current.user.guest?  
      session[:user_id] = @user.id  
      redirect_to root_url  
    else  
      render "new"  
  end  
end

Here is code from my user.rb

validates_presence_of :username, unless: :guest?
validates_uniqueness_of :username, :email, allow_blank: true

Here is the link that starts the Guest Record

<%= button_to "Try it!", users_path, method: :post %>

The errors that I am getting is are

3 errors prohibited this user from being saved:
Email can't be blank
Password can't be blank
Username can't be blank

You may be receiving the “can't be blank” errors as the parameters are not being allowed through the Devise controller as they're not listed as permitted params?

https://github.com/plataformatec/devise#strong-parameters

Check for 'Unpermitted parameters' errors in your logs to see if this is the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM