Useful for mocking out IO methods like #gets and #puts
This class is helpful when testing certain classes of software libraries that are dependent on console input and output, similar to some testing uses of Java's StringBuffer
Community contributions, tips, and corrections to the documentation. (1708 notes)
This class is helpful when testing certain classes of software libraries that are dependent on console input and output, similar to some testing uses of Java's StringBuffer
Output is buffered on most operating systems. To override this behavior, force the stdout or other io to sync
STDOUT.sync = true
It is included through ActiveModel.
see ActiveModel::Translation
eg. Person.model_name.human will return the i18n name for the model.
see for more info: ActiveModel::Translation
Also may convert original string into Jamaican.
e.g. "green moon".squeeze #=> "gren mon"
I had the @colleagues collection prepared that I wanted to be rendered within fields_for block. However it was searchlogic object with filtering/sorting applied, and the sort order was not preserved in resultant view.
<%= f.fields_for :evaluators, @colleagues do |builder| %>
<%= render "...
Here is modified EmailValidator from the example above:
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, options[:message] || :email) unless
value =~ /\\A([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})\\z/i...
Binds the named method to the receiver, returning a Method object with access to the internals of the receiver, such as self and instance variables.
It's not documented, but :anchor is an option.
polymorphic_path(commentable, :anchor => 'comments')
will return:
/article/1#comments
This code doesn't work: activemodel: attribute: post: cost: "Total cost"
Everything is OK with this one: activerecord: attributes: post: cost: "Total cost"
Eine pragmatische Lösung für das Übersetzungsproblem der Rails Methode distance_of_time_in_words(). Im Deutschen wird je nach Satzbau eine andere Ausgabe benötigt.
Vor mehr als 5 Monaten"/"Vor etwa einem Jahr" — statt wie im Original "Dauer: mehr als 5 Monate"/"Dauer: etwa 1 Jahr
or maybe
add_index :user_follows , :user
add_index :user_follows , :followed_user
The options are not documented, but of course you can use the same options than submit_tag.
Note that all non-documented options are simply passed to the input tag. Amongst other things, this allows you to change the default name attribute (commit):
form.submit 'Cancel', :name => 'cancel'...
==== Code example
named_scope :red, :joins => [:color_lis => :color], :group => "color.id", :having => ["color.xx IS NULL"]
@wiseleyb: Seems to be a typo, should be:
render_to_string(:action => "users/profile", :layout => false)
lives f.ex. here: http://rdoc.info/github/svenfuchs/i18n/master/I18n
Instead of
create_table :user_follows, :force => true do |t|
t.references :user
t.references :followed_user
t.timestamps
t.index :user
t.index :followed_user
end
Try
create_table :user_follows, :force => true do |t|
t.references :user
t.refer...
If you want to handle concurrency, this doesn't work:
a = Article.first
b = Article.first
a.increment!(:view_count)
b.increment!(:view_count)
a.reload.view_count # -> 1
b.reload.view_count # -> 1
Instead, use SQL:
def increment_with_sql!(attribute, by = 1)
raise Ar...
Just a note, ypetya's idea of using a before filter to set the primary key wont scale. transactions will eventually step on each other and probably end up with duplicate key ids, unless you have some other method to ensure uniqueness.
You'd be better off using mysql to generate the default integer...