Quantcast
Channel: Good notes posted by hosiawak
Browsing latest articles
Browse All 8 View Live

Overriding the default div class="fieldWithErrors"...

By default fields that are invalid are wrapped in:<divclass="fieldWithErrors"><inputtype="text"name="blah"></div>To override and wrap in spans instead of divs place the following in...

View Article



Overriding the default div class="fieldWithErrors"...

By default fields that are invalid are wrapped in:<divclass="fieldWithErrors"><inputtype="text"name="blah"></div>To override and wrap in spans instead of divs place the following in...

View Article

Helper method taking a block (ActionView::Helpers::TextHelper#concat)

Following the similar egzample by autonomous, here’s a simpler version when you just need to write a flexible helper method that takes a block.For example, suppose you have a method that renders a...

View Article

Useful in migrations (ActiveRecord::Base#reset_column_information)

The most common usage pattern for this method is probably in a migration, when just after creating a table you want to populate it with some default values, eg:class...

View Article

Universal partial (ActionController::PolymorphicRoutes#polymorphic_url)

polymorphic_url is very useful if you want to create an universal partial that works for more than 1 type of object passed to it.For example in you sidebar you might have a _sidebar.html.erb partial...

View Article


A catch-all format (ActionController::MimeResponds::InstanceMethods#respond_to)

If you’d like to specify a respond_to only for 1 or a few formats and render something else for all other formats, eg: (action.rss returns a feed but action.html or action.js should just render 404),...

View Article

stub_chain is very useful when testing controller code...

or any other chained method call type that you’d like to stub, example:in your controller:def new@user=current_site.users.newendin your spec:it"#new should assign a...

View Article

Naming fragment cache (ActionController::Caching::Fragments)

One of the common ways of using fragment caching is to cache content that’s shared across the site (eg. left navigation, menus, widgets etc.) that looks and works the same regardless of the name of the...

View Article

Browsing latest articles
Browse All 8 View Live




Latest Images