A small Rails cheatsheet
We constantly forget the syntax to assign CSS classes to various Rails helpers. The general idea is that most helpers take two hashes (that's the part inside curly brackets) - the first hash has specific options for the helper, the second hash gets passed on to the resulting HTML code. Thus, pay special attention to the curly brackets.
Here's a quick cheat sheet:
A simple link:
A more complicated link:
An AJAX link:
A simple form tag:
An AJAX form tag:
A simple text field:
Submit tag:
Text area:
Here's a quick cheat sheet:
A simple link:
<%= link_to "Link name", { :controller => 'controller_name',
:action => 'action_name' },
:class => 'someclass' %>
A more complicated link:
<%= link_to "Link name", { :controller => 'controller_name',
:action => 'action_name' },
{ :class => 'someclass',
:id => 'css-id',
:confirm => "Are you sure?"} %>
An AJAX link:
<%= link_to_remote "Link name", {:update => "div_to_update",
:complete => "js_on_complete",
:url => { :action => 'action_name', :id => 'some_param' }},
{:class=>"someclass"} %>
A simple form tag:
<% form_tag ({:controller => "controller_name",
:action => "action_name"},
:class => "someclass") do %>
insert code
<% end %>
An AJAX form tag:
<% form_remote_tag :update => "div_to_update",
:complete => "js_on_complete",
:url => { :action => 'action_name', :id => 'some_param' },
:html => { :class=>"someclass" } do %>
some content
<% end %>
A simple text field:
<%= text_field "object", "field", :class=>"someclass" %>
Submit tag:
<%= submit_tag "Submit", :class=>"someclass" %>
Text area:
<%= text_area "object", "field", :class=>"someclass" %>


3 Comments:
Thanks Alex! How'd you know this is exactly what I wanted. :)
I'm psychic!
Very cool - succinct but very powerful. Spent most of the afternoon looking for just this sort of information....
Post a Comment
<< Home