0

私のレポート モデルには has_many の領域があります。

新しいrespond_withスタイルを使用するように切り替える前は、areas_controller.rbは正常に機能していました。

切り替え後も、作成アクションとインデックス アクションは引き続き正常に機能しますが、「エリアが正常に更新されました」というフラッシュ メッセージが送信されたにもかかわらず、編集アクションは実際にはエリアを更新しません。なんで?

area_controller.rb :

class AreasController < ApplicationController

  respond_to :html
  filter_resource_access
  layout "wide"

  def index
    @report = Report.find(params[:report_id])
    @areas = @report.areas
    respond_with(@report, @areas)
  end

  def show
    @report = Report.find(params[:report_id])
    @area = @report.areas.find(params[:id])
    respond_with(@report, @area)
  end

  def new
    @report = Report.find(params[:report_id])
    @area = @report.areas.build
    respond_with(@report, @area)
  end

  def create
    @report = Report.find(params[:report_id])
    @area = @report.areas.build(params[:area])
    flash[:notice] = "Area was successfully created." if @area.save
    respond_with(@report, @area)
  end

  def edit
    @report = Report.find(params[:report_id])
    @area = @report.areas.find(params[:id])
    respond_with(@report, @area)
    #also tried leaving that respond_with out
  end

  def update
    @report = Report.find(params[:report_id])
    @area = @report.areas.find(params[:id])
    flash[:notice] = "Area was successfully updated." if @area.save
    respond_with(@report, @area, :location => report_area_path(@report, @area))
    # also tried respond_with(@report, @area)
  end

  def destroy
    @report = Report.find(params[:report_id])
    @area = @report.areas.find(params[:id])
    @area.destroy
    respond_with(@report, @area)
  end

end
4

1 に答える 1

1

モデルの属性を更新する必要があります。

def update
  @report = Report.find(params[:report_id])
  @area = @report.areas.find(params[:id])
  flash[:notice] = "Area was successfully updated." if @area.update_attributes(params[:area])
  respond_with(@report, @area, :location => report_area_path(@report, @area))
end
于 2012-12-16T03:46:48.547 に答える