1

ファイルに次link_toのコード行があります。html.erb

<%= link_to "no thanks" %>

このリンクをクリックして:reject、この「treating.rb」モデル ファイルで設定したステート メソッドをトリガーします。

class Treating < ActiveRecord::Base
  attr_accessible :intro, :proposed_date, :proposed_location, :requestee_id, :state

  state_machine :state, :initial => :pending do

    event :reject do
        transition [:pending] => :rejected
    end

    event :reply do
        transition [:pending, :rejected] => :replied
    end

    event :archive do
      transition [:rejected] => :archived
    end
  end
  ...
end

link_toステータスが「保留」から「拒否」に変更されることを参照している「処理中」を取得するには、コード行に何を入力すればよいですか? 私は試してみましたがaction =>method =>成功しませんでした。

4

1 に答える 1

2

これを実行するには、次のようなコントローラー アクションが必要です。

# ?.html.erb
<%= link_to "no thanks", reject_treating_path(@treating), method: :post %>

# config/routes.rb
resources :treatings do
  member do
    post :reject
  end
end

# app/controllers/treatings.rb
class TreatingsController < ApplicationController
  # POST /treatings/:id/reject
  def reject
    current_user.treatings.find(params[:id]).reject!
    redirect_to treatings_path, notice: "Treating was rejected"
  end
end

処理リソースのメンバー アクションを追加し、処理がユーザーに属していると仮定しました。

于 2012-08-10T23:44:04.673 に答える