Flowdock

Notes posted by Manfred

RSS feed
December 27, 2012 - (>= v2.3.8)
0 thanks

Example

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"]
October 26, 2011
2 thanks

Adding to the URL

If you want to use polymorphic routing for your object but you also need to specify other stuff like an anchor, you can explicitly generate the polymorphic url with extra options:

form_for @candidate,
  :url => polymorphic_path(@candidate, :anchor => 'signup')
August 6, 2009
1 thank

*Described above

The documentation is referring to the module documentation: ActionController::Cookies

June 22, 2009
3 thanks

Optional local assigns

When you have a partial with optional local assigns, for instance:

<%= render :partial => 'articles/preview' %>
<%= render :partial => 'articles/preview', :locals => { :show_call_out => true } %>

And you don’t want the partial to break when the local isn’t assigned, you can reference it through the local_assigns local variable instead of through the template binding:

<% if local_assigns[:show_call_out] %>
  <em><%= format @article.call_out %></em>
<% end %>
June 11, 2009
0 thanks

Not really helpful

When you’re trying to construct a specialized path name for a partial based on a record type you’re probably better off writing your own helper.

def topic_partial_path(topic)
  ['admin', topic.class.table_name, "#{topic.class.table_name.singularize}_as_topic"].join('/')
end