Skip to content

Instantly share code, notes, and snippets.

@jheg
Created February 18, 2015 15:16
Show Gist options
  • Save jheg/76aad705b13cb43fcbbe to your computer and use it in GitHub Desktop.
Save jheg/76aad705b13cb43fcbbe to your computer and use it in GitHub Desktop.
hitting the db
# routes
post 'todos/:id/pinned', to: 'todos#pinned', as: :pinned_todo
post 'todos/:id/unpin', to: 'todos#unpin', as: :unpin_todo
# controller
def pinned
flash[:notice] = 'Todo pinned for today'
@todo.pinned = true
@todo.save
redirect_to root_path
end
# view
<% if todo.pinned? %>
<%= link_to unpin_todo_path(todo), method: :post, class: "btn btn-sm btn-default pinned" do %>
<i class="fa fa-thumb-tack"></i>
<% end %>
<% else %>
<%= link_to pinned_todo_path(todo), method: :post, class: "btn btn-sm btn-default" do %>
<i class="fa fa-thumb-tack"></i>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment