Skip to content

Instantly share code, notes, and snippets.

@cheynewallace
Created November 4, 2017 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheynewallace/4943c19f56095de62db633a11693710a to your computer and use it in GitHub Desktop.
Save cheynewallace/4943c19f56095de62db633a11693710a to your computer and use it in GitHub Desktop.
Rails Cheatsheet
**Routes**
resources :books do
get 'search', :on => :collection
end
**Forms**
<%= form_with(model: book, local: true) do |form| %>
<%= label_tag(:name, "Name:") %>
<%= form.text_field :name %>
<%= label_tag(:description, "Description:") %>
<%= form.text_field :description %>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
**Validation**
validates :description, :presence => true
**Permit Params**
def book_params
params.fetch(:book, {}).permit(:name, :description)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment