Skip to content

Instantly share code, notes, and snippets.

@allenwlee
Last active December 18, 2015 00:59
Show Gist options
  • Save allenwlee/5700677 to your computer and use it in GitHub Desktop.
Save allenwlee/5700677 to your computer and use it in GitHub Desktop.
rails notes

##Notes

Type Sinatra Rails Notes
Partials <%= erb :_menu %> <%= render "menu" %> the underscore is implied, such that this will render the file named _menu.html.erb
Partial from another directory <%= erb :_menu %> <%= render "shared/menu" %> ---
Partial layouts --- <%= render :partial => "link_area", :layout => "graybar" %> Note that explicitly specifying :partial is required when passing additional options such as :layout. Layouts also follow the leading underscore convention, e.g., _graybar.html.erb
Pass local variables via partials, part 1 --- <%= render :partial => "form", :locals => { :zone => @zone } %>
Pass local variables via partials, part 2 --- <%= render :partial => "customer", :object => @new_customer %> Every partial has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the :object option.
Shorthand --- <%= render @customer %> If you have an instance of a model to render into a partial, you can use a shorthand syntax.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment