2015-12-29 26 views
0

我有一個評論控制器用戶可以提示評論(現在點擊它將閃爍一個句子,稍後將添加功能)。我遇到的問題是頁面正在加載,但是當我點擊鏈接時,什麼都沒有發生。無法找到控制器的Rails動作

AbstractController::ActionNotFound - The action 'tip' could not be found for CommentsController 

不過我這裏有我們的控制器動作:

def tip  
    redirect_to :back, :notice => "Thank you for the Tip. The User will Love it" 
end 

下面是尖的路線:

get "/:id/tip" => "comments#tip", :as => "tip" 
當我去到控制檯我得到這個錯誤

這裏的Link_to也是「

= link_to(tip_path(comment), :class => "story-likes-link", :remote => true, :title => "Tip comment") do 
    %i.fa.fa-money.fa-lg 
    Tip 

非常感謝你的幫助:)

編輯:整個控制器

class CommentsController < ApplicationController 
    before_action :authenticate_user! 
    before_action :set_user 
    before_action :set_resource, :except => [:destroy] 
    before_action :set_parent, :except => [:destroy] 
    before_action :set_comment, :only => [:update, :destroy] 
    respond_to :js 

    # Create the comments/replies for the books/comics 
    def create 
    @comment = current_user.comments.new(comment_params) 
    if @comment.save 
     @comment.move_to_child_of(@parent) unless @parent.nil? 
    end 
    respond_with @comment, @resource 
    end 

    # Update the comments for the user 
    def update 
    @comment.update_attributes(comment_params) 
    respond_with @comment, @resource 
    end 

    # Delete the comments for the books/comics 
    def destroy 
    @resource = @comment.commentable 
    @comment.destroy 
    respond_with @resource 
    end 

    private 

    # Permitted parameters 
    def comment_params 
    params.require(:comment).permit(:body, :commentable_id, :commentable_type, :parent_id) 
    end 

    # Set the parent resource for the comments and replies 
    def set_resource 
    if params[:comment][:commentable_type].eql?("Book") 
     @resource = Book.find(params[:comment][:commentable_id]) 
    else 
     @resource = Comic.find(params[:comment][:commentable_id]) 
    end 
    end 

    # Set the parent for the comments to make then as the child of the parent 
    def set_parent 
    @parent = params[:comment].has_key?(:parent_id) ? Comment.find(params[:comment][:parent_id]) : nil 
    end 

    # Set the comment for the source 
    def set_comment 
    @comment = Comment.find(params[:id]) 
    end 

    def tip 
     redirect_to :back, :notice => "Thank you for the Tip. The User will Love it" 
    end 

    def set_user 
    @user = User.find(params[:user_id]) 
    end 

end 
+0

你重新啓動服務器重新加載路由配置嗎?也沒有隱藏受保護或隱私部分隱藏的評論控制器的'提示'方法? –

+0

是的,我有...但我仍然得到相同的錯誤 – Jakxna360

+0

是的,對這兩個問題? –

回答

1

的問題是動作#tip方法是隱藏在私人部分,所以路由器認爲不是方法的。

好了,然後移動該方法的代碼的private關鍵字以上:

def tip 
    redirect_to :back, :notice => "Thank you for the Tip. The User will Love it" 
end 

private 

注:的行動方法不應該是地方privateprotected部分,只有public,這是Ruby的默認節類定義流程。

+0

謝謝你這麼多!就是這樣! – Jakxna360