Skip to content

Instantly share code, notes, and snippets.

@plapier
Created November 16, 2012 17:02
Show Gist options
  • Save plapier/4088995 to your computer and use it in GitHub Desktop.
Save plapier/4088995 to your computer and use it in GitHub Desktop.
Rails for Designers Cheat Sheet

#Rails

####Generate a controller and action

rails generate controller <controller name> <action>

####Change layout for entire Controller

class ProductsController < ApplicationController
  layout "inventory"
end

####Change layout for Controller ACTION

class ProductsController < ApplicationController
  def index
    render :layout => 'special_layout'
  end
end

#HTML.ERB

####Create a link

<%= link_to “Go Home”, root_path %>

####Wrap in a link

<%= link_to root_path, :id => "root" do %>
  <img />
<% end %>

####Repeat elements

<% 3.times do %>
  <li></li>
<% end %>

####Render a partial

<%= render 'sidebar' %>

####Insert and image using the asset pipeline

<%= image_tag("foo.png") %>

####Linking Javascript assets

<%= javascript_include_tag "main", "columns" %>

####Linking Stylesheet assets

<%= stylesheet_link_tag "main", "columns" %>

#CSS

####CSS Image Assets

background: image_url("image.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment