Created
February 18, 2015 15:16
-
-
Save jheg/76aad705b13cb43fcbbe to your computer and use it in GitHub Desktop.
hitting the db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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