2013-08-02 3 views
0

의견에 투표 방법에 문제가 있습니다. Im RoR에 초보자 그리고 당신의 제안을 기다리고 있습니다.Ruby on Rails에서 몽고 이드와 투표하십시오.

내가 오류는 다음과 같습니다 컨트롤러 => "의견": 행동 => "투표 (1)", /글/51f7d1279fefa5405a000003 없음 경로 일치 {에서

ActionController :: RoutingError : 클래스 => "post__button - 편집"}

내 코드 :

comment.rb

class Comment 
    include Mongoid::Document 

    field :name, type: String 
    field :email, type: String 
    field :body, type: String 
    field :up_vote, type: Integer, default: "0" 
    field :down_vote, type: Integer, default: "0" 
    belongs_to :post 

    validates_presence_of :name, :email, :body 

    def self.add_up_vote 
    self.increment(:up_vote, 1) 
    end 

    def self.add_down_vote 
    self.decrement(:down_vote, 1) 
    end 
end 

comment_controller.rb

. 
. 
. 
def vote(a) 
    @comment = Comment.find(params[:comment_id]) 
    @post = Post.find(params[:post_id]) 

    if a == 1 
     comment.add_up_vote 
     redirect_to @post 
    elsif a == -1 
     comment.add_down_vote 
     redirect_to @post 
    else 
     redirect_to @post 
    end 

    end 

routes.rb

Easyblog::Application.routes.draw do 

    authenticated :user do 
    root :to => 'home#index' 
    end 
    root :to => "home#index" 
    devise_for :users 
    resources :users 
    resources :posts do 
    resources :comments 
    member do 
     post :mark_archived 
    end 
    end 
end 

임 당신의 도움 :)

답변

0

같이 변경하려고 기다리고? 투표 방향이라고 생각합니다

avote 동작에서 제거하고 방향을 전달 경로로 사용하려면 params을 사용해야합니다.

폭스 예 :

vote_comment_path(@comment.id, dir: 1) # or dir: -1 

vote 행동에 대한 경로가없는 것보다 더. 당신은 너무처럼 설명 할 수 있습니다

resources :comments do 
    put :vote, as: :member 
end 

UPD 내가 당신의 경로 안내 http://guides.rubyonrails.org/routing.html

action 다음 읽기를 추천하는 것은 유효하지 않습니다.

$ rake routes 
+0

가 변경되어 여전히 동일한 문제가 발생합니다. – user2646329

+0

나는 메소드 (투표)가 '게시'보기 (app/views/posts/show.haml)에 다음과 같이 추가되어야한다고 덧붙여 야합니다. @ post.comments.each do | comment | . . . % td = link_to "예", 컨트롤러 : "설명", 동작 : "투표 (의견, 1)", 수업 : 'post__button - 수정' – user2646329

+0

내 대답에 대한 설명을 추가했습니다. – ck3g

0

a 여기 이것은 무엇

Easyblog::Application.routes.draw do 

    resources :posts do 
    resources :comments do 
     match :vote 
    end 
    member do 
     post :mark_archived 
    end 
    end 
end 
+0

아니, 여전히 같은 문제를보십시오. – user2646329

0

당신이 개봉 된 경로

resources :posts do 
    resources :comments do 
    member do 
     post 'vote' 
    end 
end 
member do 
    post :mark_archived 
end 
0

필요가 없습니다에를이 뭔가를 시도 할 수 있습니다 : 당신은 연결해야 당신이 rake routes 명령을 확인할 수 있습니다 다를 수 있습니다

= link_to 'Yes', vote_comment_path(comment, dir: 1), method: :put 

vote_comment_path처럼 보인다 자신의 투표 시스템을 구축하십시오. voteable_mongo gem