guides.rubyonrails.org

When your Rails controller calls render, you can pass a :status option for the HTTP status code: render 'results', status: 400 All important status codes also have a symbol alias...

Do you have page caching enabled for the development environment and there are cached pages lying around in public/?

weblog.rubyonrails.org

jQuery as new default Javascript library, streaming response support, attr_accessible with roles, prepared statements, easier migrations.

...by calling #dup on it: user = User.find(3) user.freeze unfrozen_user = user.dup Notes for Rails 2 users There is a bug in Rails 2.3.x where duping an ActiveRecord instance...

...transactions and locking. Examples will be given for the ActiveRecord ORM (from Ruby on Rails), but apply to all technologies. Use transactions to group related changes Use a transaction to...

...than a single database row, you should always use a transaction. Note that in Rails, ActiveRecord::Base#save automatically opens a transaction. Hence changes you make in callbacks, nested attributes...

If you use a form (or form fields) multiple times inside one view, Rails will generate the same id attributes for fields again. This card presents you with a way...

...to Cucumber that helps integration-testing command line tools. When your tests involve a Rails test application, your tool's Bundler environment will shadow that of the test application. To...

...param is a string and you don't get the magic type casting that Rails would give you if it was an actual database column. E.g. when you set an...

...param is a string and you don't get the magic type casting that Rails would give you if it was an actual database column. One effect is that when...

Submit buttons in Rails come with a useful option :disable_with which will disable the button when clicked and change its label to something like "Please wait...". An annoying side...

...is to re-enable the submit button before leaving the page. This works in Rails 3: $(window).unload(function() { $.rails.enableFormElements($($.rails.formSubmitSelector...

...just upgraded to Bundler 10.0.10 you might get the following error when bringing up Rails: /usr/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 17 column 14 (Psych::SyntaxError...

...This is caused by Rails localization files (en.yml, de.yml, etc.) using symbols for various translation strings, and Bundler 10.0.10 defaults to a new YAML engine which cannot handle symbols.

stackoverflow.com

...a low-level Ruby message like Fix: "undefined method `bytesize' for #" or the standard Rails error box. You will not get an exception notification per e-mail or Airbrake.

...ordered by ID because they need to be able to iterate in batches. Modern Rails will raise an error if you try order yourself. If you are on Rails...

...aware that find calls inside the block are implicitly scoped. This is fixed in Rails...

github.com

Leads to awesomeness and unicorns when used in production.

makandra dev

...treats cookies with SameSite=None like SameSite=Strict How to set a SameSite cookie Rails (session configuration) In config/initializers/session_store.rb, add the options secure: true, same_site: :strict|:lax. To set...

...none you need Rack 2 (i.e. Rails 5). Rails 6.1 will set SameSite=Lax; on default. Rails Custom cookies are set with cookies[:cookie_name] = 'value' or = { value: 'value', path...

island94.org

GoodJob is a new background worker gem. It's compatible with ActiveJob. We're huge fans of Sidekiq for its...

ActiveSupport::Memoizable will be removed from Rails and has a lot of strange caveats that will ruin your day. Use the Memoizer gem instead. It works in all past and...

...future Railses and has none of the annoying "features" of ActiveSupport::Memoizable. It just does memoization and does it well. The syntax is similiar also: class Foo include Memoizer

makandra dev
github.com

...x versions of Capybara does not support Ruby 1.8.x anymore removes confusion with Rails' built in integration tests (you put capybara rspec integration tests into the spec/feature/... folder) and...

Once Rails knows a given string is html_safe, it will never escape it. However, there may be times when you still need to escape it. Examples are some safe...

...to turn your string into an unsafe string to get the escaping love from Rails: embed = javascript_tag('var foo = 1337;') # This is an html_safe SafeBuffer embed.to_str # This...

makandra dev

...want to uninstall newer ones): bundle _1.0.10_ -v Bundler version 1.0.10 An example is rails 3.2, which freezes bundler at version ~> 1.0: Bundler could not find compatible versions for gem...

In Gemfile: rails (~> 3.2) was resolved to 3.2.0, which depends on bundler (~> 1.0) Current Bundler version: bundler (1.13.6) You can solve this with: gem install bundler -v 1.0.10

...some actions protected by SSL, some not. A popular way to implement this in Rails is using the ssl_requirement plugin by DHH, which redirects a requests from HTTP to...

...While in_groups and in_groups_of are provided by Rails this also works in pure Ruby. If it does not for you, require 'enumerator...

stackoverflow.com

From Rails 3.0.9, there is a method Hash#to_query that will turn a Hash into a query string: >> {:a => "a", :b => ["c", "d", "e"]}.to_query

...or from the public folder with javascript_include_tag. The subtle difference that tells rails how to build the path correctly is a single slash at the beginning of the...

...stylesheet in /assets you need to add it to the list of assets that Rails will precompile...