Created
June 19, 2013 18:10
-
-
Save Apane/5816494 to your computer and use it in GitHub Desktop.
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
<div class="haiku"> | |
<%= simple_format haiku.content %> | |
<em> | |
-- <%= haiku.user.name %> | |
| <%= pluralize haiku.reputation_for(:votes).to_i, "vote" %> | |
| <%= link_to "up", vote_haiku_path(haiku, type: "up"), method: "post" %> | |
| <%= link_to "down", vote_haiku_path(haiku, type: "down"), method: "post" %> | |
</em> | |
</div> |
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
Routing Error | |
No route matches [GET] "/haikus/1/vote" | |
Try running rake routes for more information on available routes. |
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
class Haiku < ActiveRecord::Base | |
attr_accessible :content | |
belongs_to :user | |
has_reputation :votes, source: :user, aggregated_by: :sum | |
end |
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
class HaikusController < ApplicationController | |
before_filter :authorize, except: [:index, :show] | |
def index | |
@haikus = Haiku.all | |
end | |
def show | |
@haiku = Haiku.find(params[:id]) | |
end | |
def create | |
@haiku = current_user.haikus.create!(params[:haiku]) | |
redirect_to @haiku, notice: "Successfully created haiku." | |
end | |
def vote | |
value = params[:type] == "up" ? 1 : -1 | |
@haiku = Haiku.find(params[:id]) | |
@haiku.add_or_update_evaluation(:votes, value, current_user) | |
redirect_to :back, notice: "Thank you for voting" | |
end | |
end | |
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
Youhaiku::Application.routes.draw do | |
get 'signup', to: 'users#new', as: 'signup' | |
get 'login', to: 'sessions#new', as: 'login' | |
get 'logout', to: 'sessions#destroy', as: 'logout' | |
resources :users | |
resources :sessions | |
resources :haikus do | |
member { post :vote } | |
end | |
root to: 'haikus#index' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment