我正在尝试将名为 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
结尾