Returns a checkbox tag tailored for accessing a specified attribute (identified by method ) on an object assigned to the template (identified by object ). This object must be an instance object (@object) and not a local object. It's intended that method returns an integer and if that ...
Delegates to I18n#translate but also performs three additional functions. First, it will ensure that any thrown MissingTranslation messages will be turned into inline spans that: * have a "translation-missing" class set, * contain the missing key as a title attribute and * a titleized...
Specifies a many-to-many relationship with another class. This associates two classes via an intermediate join table. Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give...
active_support/core_ext/hash/except active_support/core_ext/hash/reverse_merge active_support/core_ext/hash/slice active_support/core_ext/enumerable active_support/core_ext/array/extract_options active_support/core_ext/module/remove_method active_support/inflector action_dispatch/rout...
Converts the array to a comma-separated sentence where the last element is joined by the connector word. You can pass the following options to change the default behavior. If you pass an option key that doesn't exist in the list below, it will raise an ArgumentError . Options :words_c...
Destroys the records supplied and removes them from the collection. This method will always remove record from the database ignoring the :dependent option. Returns an array with the removed records. class Person < ActiveRecord::Base has_many :pets end person.pets.size # => 3 person.pe...
Provides a way to track changes in your object in the same way as Active Record does. The requirements for implementing ActiveModel::Dirty are: include ActiveModel::Dirty in your object. Call define_attribute_methods passing each method you want to track. Call attr_name_will_change! b...
Escapes carriage returns and single and double quotes for JavaScript segments. Also available through the alias j(). This is particularly helpful in JavaScript responses, like: $('some_element').replaceWith('<%=j render 'some/element_template' %>');
select_tag "people", options_from_collection_for_select(@people, "id", "name") # <select id="people" name="people"><option value="1">David</option></select> select_tag "people", "<option>David</option>".html_safe # => <select id="people" name="people"><option>David</option></select> s...
Returns an instance of the specified klass with the attributes of the current record. This is mostly useful in relation to single-table inheritance structures where you want a subclass to appear as the superclass. This can be used along with record identification in Action Pack to all...
# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute. date_select("article", "written_on") # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute, # with the year in the year drop d...
Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record o...
Bite-sized separation of concerns We often find ourselves with a medium-sized chunk of behavior that we'd like to extract, but only mix in to a single class. Extracting a plain old Ruby object to encapsulate it and collaborate or delegate to the original object is often a good choice,...
Specifies a many-to-many relationship with another class. This associates two classes via an intermediate join table. Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give...
ActionController::Metal is the simplest possible controller, providing a valid Rack interface without the additional niceties provided by ActionController::Base . A sample metal controller might look like this: class HelloController < ActionController::Metal def index self.response_bo...
Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index , show , new , edit , create , update and destroy actions, a resourceful route declares them in a single line of code: resour...
Implements a hash where keys :foo and "foo" are considered to be the same. rgb = ActiveSupport::HashWithIndifferentAccess.new rgb[:black] = '#000000' rgb[:black] # => '#000000' rgb['black'] # => '#000000' rgb['white'] = '#FFFFFF' rgb[:white] # => '#FFFFFF' rgb['white'] # => '#FFFFFF' ...
Find by id - This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). If no record can be found for all of the listed ids, then RecordNotFound will be raised. If the primary key is an integer, find by id coerces its arguments using to_i . Person....
Form helpers are designed to make working with resources much easier compared to using vanilla HTML . Typically, a form designed to create or update a resource reflects the identity of the resource in several ways: (i) the url that the form is sent to (the form element's action attrib...
select_tag "people", options_from_collection_for_select(@people, "id", "name") # <select id="people" name="people"><option value="1">David</option></select> select_tag "people", "<option>David</option>".html_safe # => <select id="people" name="people"><option>David</option></select> s...
Provides a modified Hash that you can include in your object for handling error messages and interacting with Action Pack helpers. A minimal implementation could be: class Person # Required dependency for ActiveModel::Errors extend ActiveModel::Naming def initialize @errors = ActiveMo...
Shortcut for Rack::Test::UploadedFile.new(File.join(ActionController::TestCase.fixture_path, path), type) : post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png') To upload binary files on Windows, pass :binary as the last parameter. This will not affect ...
You're testing whether a transaction works correctly. Nested transactions don't commit until all parent transactions commit, particularly, the fixtures transaction which is begun in setup and rolled back in teardown. Thus, you won't be able to verify the results of your transaction un...
Module ActiveModel::AttributeMethods::ClassMethods activemodel/lib/active_model/attribute_methods.rb
Delegates to I18n#translate but also performs three additional functions. First, it will ensure that any thrown MissingTranslation messages will be turned into inline spans that: * have a "translation-missing" class set, * contain the missing key as a title attribute and * a titleized...
Returns the tail of the array from position . %w( a b c d ).from(0) # => %w( a b c d ) %w( a b c d ).from(2) # => %w( c d ) %w( a b c d ).from(10) # => nil %w().from(0) # => nil [ show source ] # File activesupport/lib/active_support/core_ext/array/access.rb, line 12 12: def from (pos...
Allows to choose which attributes should be whitelisted for mass updating and thus prevent accidentally exposing that which shouldn’t be exposed. Provides two methods for this purpose: require and permit . The former is used to mark parameters as required. The latter is used to set th...
<%= button_to "New", action: "new" %> # => "<form method="post" action="/controller/new" class="button_to"> # <div><input value="New" type="submit" /></div> # </form>" <%= button_to [:make_happy, @user] do %> Make happy <strong><%= @user.name %></strong> <% end %> # => "<form method="...
Reflection enables to interrogate Active Record classes and objects about their associations and aggregations. This information can, for example, be used in a form builder that takes an Active Record object and creates input fields for all of the attributes depending on their type and...
Action caching is similar to page caching by the fact that the entire output of the response is cached, but unlike page caching, every request still goes through Action Pack. The key benefit of this is that filters run before the cache is served, which allows for authentication and ot...