2016-10-21 6 views
0

私は5アプリ(APIモード)を持っています。私はフラグのコメント機能をブートストラップしています。コメント付きの属性と無効な属性をコメント表に追加しました。なぜなら、コメントを完全に破棄するのではなく、無効になっている場合は前面に非表示にしたいからです。電子メールからapiに更新アクションを送信できません

コメントがフラグされているとき、私はコメントとそれに関するいくつかのメタデータ、およびdisabled属性をtrueに更新するための電子メールを(ActionMailerを介して)自分自身に送信します。

私のメールでこのリンクをクリックすると、属性が更新されないという問題があります。ここで

それを明確にするコードは次のとおりです。

routes.rbを:

resources :comments, only: [:create, :update] do 
    member do 
    post 'flag' 
    end 
end 

コントローラ/ API/V1/comments_controller.rb:

def update 
    @comment = Comment.find(params[:id]) 
    new_status = @comment.disabled ? false : true 

    # binding.pry => I'm not even reaching that method 

    if @comment.update(disabled: new_status) 
     CommentDisabledMailer.send_comment_disabled_confirmation(@comment).deliver_now 
     redirect_to "https://media.giphy.com/media/YfGkjrnVIk3jq/giphy.gif" # a funny gif url 
    else 
     render json: { errors: @comment.errors.messages }, status: :unprocessable_entity 
    end 
end 

def flag 
    @comment.update(flagged: @comment.flagged + 1) 
    render json: @comment, serializer: Api::V1::CommentSerializer, status: 201, root: nil 
    FlagMailer.send_flag_mail(@comment).deliver_now 
end 

ビュー/ flag_mailer/send_flag_mail .html.erb:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    </head> 
    <body> 
    <!-- some meta data about my comment --> 

    <h2> <%= link_to "Disabled this comment", api_v1_comment_url(@comment), method: :put, action: :update %> </h2> 

    </body> 
</html> 

私は郵便配達員を通じてコメントにフラグを立てると私はメールを受け取るが、フラグ付きの属性は更新されているが、メールで「このコメントを無効にする」をクリックすると、レールのエラーで新しいウィンドウが開きます: No route matches [GET] "/api/v1/comments/5"コメントは更新されず、コメントが無効になっていることを確認するメールが表示されません(コントローラのupdateメソッド参照)。

何か不足していますか?

+1

あなたのルートがPOSTルートで試すことができます。 RailsはJSを使用して通常は 'link_to(...)method::post'をクリックで送信されるフォーム(通常のリンクは常にGETリクエストを生成する)に置き換えますが、リンクはアプリケーションコンテキスト外の電子メールで表示されますレールの控えめなjavascriptの魔法のどれも起こっていない。 put/postリクエストが電子メールで機能しない理由を説明するこの質問に対する回答を確認してください:http://stackoverflow.com/questions/25573000/rails-3-2-link-to-in-email-with-method-プット・スティル・プロダクション・ゲット・リクエスト – omnikron

答えて

0

あなたはこの

<a href="<%= api_v1_comment_url(@comment) %>" data-method="put">Disabled this comment</a> 
関連する問題