1

我正在尝试将名为 listing_status 的属性的状态从 Active 更改为 Terminated。我像这样尝试过,但它不起作用。知道我做错了什么吗?

<%=link_to("Terminate", listing_path(listing, :listing_status => "Terminated"), :method => :put, :confirm => "Are you sure you want to TERMINATE this listing?", :class => 'btn btn-danger')%>

列出控制器更新操作

def update  
@listing = Listing.find(params[:id])

respond_to do |format|
  if @listing.update_attributes(params[:listing])
    if @listing.listing_status == "Active"
        @listing.sold.destroy if @listing.sold
    end 
    flash[:notice] = 'house was successfully updated'
    format.html { redirect_to :action=> "show" }
    format.json { head :no_content }
  else
    format.html { render action: "edit" }
    format.json { render json: @listing.errors, status: :unprocessable_entity }
  end
end

结尾

4

1 回答 1

1

您将状态传递为params[:listing_status],但尝试使用 更新列表params[:listing]。由于没有具有该名称的参数,因此不会发生更新。

您可能希望更改链接以适应预期的参数格式:

<%= link_to("Terminate", 
  listings_path(listing, 'listing[listing_status]' => "Terminated"),
  :method => :put, :confirm => "Are you sure you want to TERMINATE this listing?", 
  :class => 'btn btn-danger') %>
于 2013-03-15T20:11:57.337 回答