How can I keep my Heroku application private?

My cheap solution has been implementing a before_filter to request an HTTP authentication before every action is executed. This solution works well along other authentication layers – Devise or others. USERS = { “user” => “secret” } before_filter :authenticate def authenticate authenticate_or_request_with_http_digest(“Application”) do |name| USERS[name] end end Whenever other peers land at yourdomain.heroku.com, they are … Read more

Rails 3 with Devise for Authentication – How do I manually create a user?

The skip_confirmation! method is available to any confirmable model. @user = User.new params[:user] @user.skip_confirmation! # Sets confirmed_at to Time.now, activating the account @user.save The user account will be activated though. If you don’t want that, continue reading. Devise uses conditional callbacks to generate the confirmation token and send the email. The callbacks will be called … Read more

Rails, Devise, Rspec: Undefined method ‘sign_in’

Did you recently upgrade to RSpec 3 like I did? This is from the RSpec 3 documentation: Automatically Adding Metadata RSpec versions before 3.0.0 automatically added metadata to specs based on their location on the filesystem. This was both confusing to new users and not desirable for some veteran users. In RSpec 3, this behavior … Read more

Devise: Create users without password

There are at least two ways to do what you want: Method 1: Overload Devise’s password_required? method class User < ActiveRecord::Base attr_accessor :skip_password_validation # virtual attribute to skip password validation while saving protected def password_required? return false if skip_password_validation super end end Usage: @user.skip_password_validation = true @user.save Method 2: Disable validation with validate: false option: … Read more

Profile model for Devise users?

Assuming you have a User model with a has_one Profile association, you simply need to allow nested attributes in User and modify your devise registration view. Run the rails generate devise:views command, then modify the devise registrations#new.html.erb view as shown below using the fields_for form helper to have your sign up form update your Profile … Read more

Devise Not Validating Password/Password Confirmation

If you want Devise to do validations, you need to add the :validatable module to your model. This is fairly easy to do, just add :validatable to the list of module in the devise call, so your model says: devise :database_authenticatable, :lockable, :registerable, :recoverable, :rememberable, :trackable, :validatable This will make devise add validations. Another easy … Read more

Seeding users with Devise in Ruby on Rails

You have to do like this: user = User.new user.email=”test@example.com” user.encrypted_password = ‘#$taawktljasktlw4aaglj’ user.save! Read this guide to understand what mass-assignment is: http://guides.rubyonrails.org/security.html I am wondering why do have to directly set the encrypted password. You could do this: user.password = ‘valid_password’ user.password_confirmation = ‘valid_password’

Rails Devise: after_confirmation

I’m using Devise 3.1.2, it has a placeholder method after_confirmation which is called after the confirmation finished successfully. We just need to override this method in User model. class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable # Override Devise::Confirmable#after_confirmation def after_confirmation # Do something… end end See: Devise 3.5.9 Source Code: … Read more

Multiple user models with Ruby On Rails and devise to have separate registration routes but one common login route

Okay, so I worked it through and came to the following solution. I needed to costumize devise a little bit, but it’s not that complicated. The User model # user.rb class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :email, :password, :password_confirmation, :remember_me belongs_to :rolable, :polymorphic => true end The Customer model … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)