for rails >= 3
template_root= is deprecated, use prepend_view_path instead
source: ActionMailer/DeprecatedApi/ClassMethods/template_root
Community contributions, tips, and corrections to the documentation. (1708 notes)
template_root= is deprecated, use prepend_view_path instead
source: ActionMailer/DeprecatedApi/ClassMethods/template_root
The Rails engines getting started guide discusses the usage of isolate_namespace: http://edgeguides.rubyonrails.org/engines.html
While this example is not so obvious on first look what the block passed does, here's a small explanation:
when the block is passed to this function, the uniqueness is checked based on a value returned by that block.
For example if it's array of objects with "user_id" method, then this would be:...
(Note this was an issue in Ruby 1.9.2, 1.9.3 has been corrected, not sure why the generated doc is still incorrect)
Both exist? and exists? use the same underlying C function
==== file.c, line 5444 define_filetest_function("exist?", rb_file_exist_p, 1); define_filetest_function("exists?",...
patrickberkeley's method works great. I corrected the grammar a bit for inflection (the singular error).
==== application_helper.rb def pluralize_without_count(count, noun, text = nil) if count != 0 count == 1 ? "an #{noun}#{text}" : "#{noun.pluralize}#{text}" end end
This...
When needing to include a helper method inside of a controller, instead of including the ENTIRE helper module, simply use this method like so:
module ApplicationHelper
def fancy_helper(str)
str.titleize
end
end
class MyController < ApplicationController
def index...
@hayafirst — it is possible to remove that ":" or change it to something else. Just pass :time_separator option. Inspect ActionView::Helpers::DateTimeSelector#separator method for more.
An +:onchange+ call can be made using the Rails 3 jquery-ujs helper in the form: select_tag( name, option_tags, misc_html_options, html_5_data-stuff) For example: select_tag( "my_tag_id", get_ids(@entity), class: "progress_and_message", data: { remote: true, url: url_for( act...
NOTE: you pass all the keys and values in one long list:
fruit = ActiveSupport::OrderedHash[
'apple', 'Apple',
'banana', 'Banana',
'kiwi', 'Kiwi fruit',
]
fruit.keys => ["apple", "banana", "kiwi"]
Including module in a class does not automatically over-write methods defined with the same name.
Ex:
module Mod def exit(code = 0) puts "Exiting with code #{code}" super end end
class OriginalClass include Mod def exit puts "Original message" end end
OriginalClas...
On some systems:
"1".crypt('aa') => "aacFCuAIHhrCM"
"12".crypt('aa') => "aa8dJzr7DFMPA"
"123".crypt('aa') => "aamrgyQfDFSHw"
"1234".crypt('aa') => "aatxRPdZ/m52."
"12345".crypt('aa') => "aa...
====code
def test_should_signin_first_before_add_post
get "/admin/posts/new"
follow_redirect!
end
post_via_redirect("sessions", {:user=>{:email=> user.email, :password => user.password}})
Even though validations are called, virtual attributes are ignored.
I found code that had a :find_by option on belongs_to. I'm sure it's more or less self explanatory, but I couldn't find it listed anywhere as an option.
My bad, belongs_to was in a controller, not a model.
Note that converting from Date to String and back again is not necessarily symmetric, because the conversion to string may result in a format that is not properly converted by to_date.
For one thing, to_date sets the century argument in _parse to false. Thus if the default date format has a tw...
From utc:
Returns a Time or DateTime instance that represents the time in UTC.
Seems to have changed in 3.1.0
You can still use collect when you nest +content_tag+ . Just +join+ the collection in the end and remember to add +html_safe+ if you don't want your html to be escaped.
a = ['a','b','c']
content_tag(:ul, :class => 'a class') do
a.collect do |item|
content_tag(:li, item)
end.j...