ruby - What's the difference between request.remote_ip and request.ip in Rails?

request.ip returns the client ip even if that client is a proxy. request.remote_ip is smarter and gets the actual client ip. This can only be done if the all the proxies along the way set the X-Forwa... Read More

Run migrations from rails console

In the console: ActiveRecord::Migration.remove_column :table_name, :column_name To update your schema.rb file after running migrations from the console, you must run rails db:migrate... Read More

ruby - rails console doesn't load due to libreadline

Ran across this today, to solve it I did: brew rm -f readline brew install readline brew link readline --force Hope it helps. EDIT: I recently ran into this problem again (after downgrading Ruby) s... Read More

redirects - To WWW or not to WWW

Use www as the default one and force redirect to www with this htaccess script: RewriteEngine on RewriteCond %{HTTP_HOST} !^$ RewriteRule ^(.*)$$1 [R=301] This... Read More

ruby on rails - Determine if ActiveRecord Object is New

An ActiveRecord object lifecycle: new record item = item.new_record? #=> true persisted item.persisted? #=> true changed = "other" item.changed? #=> true destroyed item.... Read More

How to restart a rails server on Heroku?

The answer was: heroku restart -a app_name # The -a is the same as --app Easily aliased with alias hra='heroku restart --app ' Which you can make a permanent alias by adding it to your .bashrc or... Read More

Renaming table in rails

Remember that in Rails >= 3.1 you can use the change method. class RenameOldTableToNewTable < ActiveRecord::Migration def change rename_table :old_table_name, :new_table_name end end... Read More

Ruby syntax: break out from 'each.. do..' block

You can break with the break keyword. For example [1,2,3].each do |i| puts i break end will output 1. Or if you want to directly return the value, use return. Since you updated the question, here... Read More

ruby on rails - Passing parameters through OmniAuth

After struggling with all the above answers, I figured out what to do regarding Facebook , which by default does not display the params in request.env["omniauth.auth"]. So -- If you are using a quer... Read More

ruby - Rails validation required numericality even though presence is not set to true

validates :network_id, :numericality => true, :allow_nil => true... Read More