Changing the Message
For Change the default message:
==== Code example
validates :invoice_number, :presence => {:message => 'The invoice number must be informed.'}
Community contributions, tips, and corrections to the documentation. (1708 notes)
For Change the default message:
==== Code example
validates :invoice_number, :presence => {:message => 'The invoice number must be informed.'}
Another shorthand way of assigning key, value pairs:
Hash[one: 1, two: 2] #=> {:one=>1, :two=>2}
Would it be possible to do something like: rescue_from Exception, :with => my_handler, :unless => request.local?
@tordans You asked your question 3 years ago, but in any case, should anyone have that same issue, you can manage that with:
- unless content_for(:footer).blank?
yield(:footer)
- else
== render "layouts/footer_big"
content_for(:x) defaults to an empty string, that's why you need to...
This has been deprecated. See this note on memoize : http://apidock.com/rails/ActiveSupport/Memoizable/memoize#1317-this-has-been-deprecated-replace-with-Memoist
In Rails 3.2, memoize has been deprecated. In edge Rails, it has been removed.
The commit when it was deprecated: http://github.com/rails/rails/commit/36253916b0b788d6ded56669d37c96ed05c92c5c
A Stack Overflow question about this change: http://stackoverflow.com/q/9132197/578288
I personally disag...
See also DateTime#strftime and Date#strftime . (They work similarly, but have different APIdock notes.)
See also Time#strftime and DateTime#strftime . (They work similarly, but have different APIdock notes.)
See also Time#strftime and Date#strftime . (They work similarly, but have different APIdock notes.)
If you want to add additional parameters to the form_for helper, but still want to use one form for both your "create" and your "update" actions, you can add the additional parameters to the :url option, but you need to omit the :controller and :action keys.
form_for(@user, :url => {:param1 =>...
== Array
class Array def included_in? array array.to_set.superset?(self.to_set) end end
[1,2,4].included_in?([1,10,2,34,4]) #=> true
given: order active record class with "state" string field
class Order < ActiveRecord::Base
def state
@state ||= ActiveSupport::StringInquirer.new(read_attribute(:status))
end
end
order = Order.new(state: "initial")
order.state.initial? #=> true
order.state.paid...
In addition to stevo's note, in Rails 3 you can also do:
model_instance.errors.add(:base, "Msg")
The following date format won't be parsed correctly:
'06/15/2008'.to_date
Use this instead:
Date.strptime("6/15/2012", '%m/%d/%Y')
e.g.
str = ActiveSupport::StringInquirer.new('test')
str.test? # => true
str.foobar? # => false
Over the weekend I kept running into instances where I was writing code like this:
==== Code example arr = ['hello', 'world']
if arr.length > 2
else
end
So I ended up extending the core and adding an instance method of more_than?
==== Code...
Or you can use this way:
<%= submit_tag "Login", data: { disable_with: "Please wait.." } %>
Since version 3.2.5 you should not use :disable_with.
Use this: <%= submit_tag "Login", 'data-disable-with' => "Please wait.." %>
By just adding a - symbol.
%-I %-d
It's an old problem, reported back in 2010, just reopened issue: