Devise limit one session per user at a time

This gem works well: https://github.com/devise-security/devise-security Add to Gemfile gem ‘devise-security’ after bundle install rails generate devise_security:install Then run rails g migration AddSessionLimitableToUsers unique_session_id Edit the migration file class AddSessionLimitableToUsers < ActiveRecord::Migration def change add_column :users, :unique_session_id, :string, limit: 20 end end Then run rake db:migrate Edit your app/models/user.rb file class User < ActiveRecord::Base devise :session_limitable … Read more

How does Rails ActiveRecord chain “where” clauses without multiple queries?

The where method returns an ActiveRecord::Relation object, and by itself this object does not issue a database query. It’s where you use this object that matters. In the console, you’re probably doing this: @person = Person.where(name: “Jason”) And then blammo it issues a database query and returns what appears to be an array of everyone … Read more

Multiple databases in Rails

Rails by default is not designed for a multi-database architecture and, in most cases, it doesn’t make sense at all. But yes, you can use different databases and connections. Here’s some references: ActiveRecord: Connection to multiple databases in different models Multiple Database Connections in Ruby on Rails Magic Multi-Connections

Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]

You need to add the following line at every environment: config.action_mailer.default_url_options = { :host => “yourhost” } That way, it can work in all environments and could be different from environment to environment. For example: development.rb config.action_mailer.default_url_options = { :host => “dev.yourhost.com” } test.rb config.action_mailer.default_url_options = { :host => “test.yourhost.com” } production.rb config.action_mailer.default_url_options = { … Read more

Heroku/devise – Missing host to link to! Please provide :host parameter or set default_url_options[:host]

You need to add this to your environment.rb config.action_mailer.default_url_options = { :host => ‘localhost’ } Make sure you change host to your production url and keep it localhost for development. This is for the mailer, it needs a default email to send out notices such as confirmations etc… You should check the logs on the … Read more

curl : (1) Protocol https not supported or disabled in libcurl

Got the answer HERE for windows, it says there that: curl -XPUT ‘http://localhost:9200/api/twittervnext/tweet’ Woops, first try and already an error: curl: (1) Protocol ‘http not supported or disabled in libcurl The reason for this error is kind of stupid, Windows doesn’t like it when you are using single quotes for commands. So the correct command … Read more

Rails 4 images not loading on heroku

I needed to combine several solutions to make this work, here is what I did: Gemfile gem ‘rails_12factor’, group: :production in my Heroku console heroku labs:enable user-env-compile -a yourapp production.rb config.serve_static_assets = true config.action_dispatch.x_sendfile_header=”X-Accel-Redirect” config.assets.compile = true I didn’t need to precompile the assets locally.