Skip to content

Instantly share code, notes, and snippets.

@Apane
Created June 19, 2013 18:10
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 Apane/5816494 to your computer and use it in GitHub Desktop.
Save Apane/5816494 to your computer and use it in GitHub Desktop.
<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>
Routing Error
No route matches [GET] "/haikus/1/vote"
Try running rake routes for more information on available routes.
class Haiku < ActiveRecord::Base
attr_accessible :content
belongs_to :user
has_reputation :votes, source: :user, aggregated_by: :sum
end
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
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