2016-05-18 3 views
0

私はフィードバックシステムを作成しました。アーカイブのためのフィードバックを得ようとしています。私は複数の異なる設定を試みましたが、うまく動作しないようです。私はエラーを受け取っていません、そして、私は通知を受けているようにコントローラのアクションを打っているようです。ただし、ブール値はDBでは変更されず、特定のフィードバックは非表示になりません。Rails 4で特定のフィードバックをアーカイブしようとしています

助けていただけたら幸いです!

  • 私はテーブルにArchiveブール値を追加しました。
  • アーカイブのルートを作成しました。
  • アーカイブ用のコントローラアクションを作成しました。

ここでは私のコードです:

また
**Controller:** 

def archive_feedback 
@listing_feedback = ListingFeedback.find(params[:id]) 

respond_to do |format| 
    format.html { redirect_to listing_listing_feedbacks_path, notice: "That feedback has been archived." } 
    format.json { render :index } 
end 
end 

**Routes: (My feedback feature is using nested resources)** 

resources :listings do 
    member do 
    get 'like' 
    get 'unlike' 
    get 'duplicate' 
    get 'gallery' 
    delete 'gallery' => 'listings#clear_gallery' 
    get 'manage_photos' 
    get 'craigslist' 
    get "add_to_collection" 
    end 
    resources :listing_feedbacks do 
    member do 
    put 'archive_feedback' 
    end 
end 
end 

**Index.html.erb:** 

<p><%= link_to 'Archive', controller: "listing_feedbacks", action: "archive_feedback", id: listing_feedback.id, archive: :true, method: :put %></p> 

、どのように私はそれがアーカイブされた後のフィードバックを非表示にすることになるだろうか?

+1

.... てみてくださいする@ listing_feedback.update_attributes(:属性=>値) – Boltz0r

+0

更新するトリングされている属性の名前は何ですか?コントローラでただ更新する – Thorin

答えて

0

あなたはarchive_feedback方法で@listing_feedbackを更新していません。

def archive_feedback 
@listing_feedback = ListingFeedback.find(params[:id]) 
@listing_feedback.update(archive: true) 

respond_to do |format| 
    format.html { redirect_to listing_listing_feedbacks_path, notice: "That feedback has been archived." } 
    format.json { render :index } 
end 
end 
0

コントローラのリクエストパラメータに新しいアーカイブ属性を追加しましたか?
そうでない場合は、DBに保存されません。

あなたは、コントローラには何も保存していない
private 
def listing_feedback_params 
params.require(:listing_feedback).permit :archive 
end 
-1
I think .. 

you have to write as below in controller 


def archive_feedback 
@listing_feedback = ListingFeedback.find(params[:id]) 

@listing_feedback.destroy 
    or 
@listing_feedback.update_attribute(archive: true) 

respond_to do |format| 
    format.html { redirect_to listing_listing_feedbacks_path, notice: "That feedback has been archived." } 
    format.json { render :index } 
end 
end 
関連する問題