如何通过link_to_remote更新a:has_one值?

时间:2010-09-25 03:17:00

标签: ruby-on-rails has-one link-to-remote

我希望能够更改模型联系人的:status_contact的值(has_one:status_contact

以下是link_to_remote:

的摘录
    <%= link_to_remote "Responded - Positive",
              :url => contacts_url(@contact, :status => 'positive response'),
              :update => "status" %>
    <span id="status"></span>

以下是Contact.rb的相关模型定义

  has_one :status_contact
  alias_attribute :status, :status_contact

似乎从错误中我可能需要创建特殊路线?

http://localhost:3000/contacts/22
404 Not Found

如何获取它以便当我点击link_to_remote时,它会通过ajax更改值?

更新:新错误 我做了以下改动:

:url=> contact_path(@contact, :status => 'positive response')

我不确定它在控制器中正在寻找什么动作。我确实有'更新'动作。这是通过Firebug控制台传递的URL:

http://localhost:3000/contacts/16?status=positive+response

<h1>Unknown action</h1>
<p>No action responded to 16. Actions: build_date_from_params, create, destroy, edit, index, message_sub, new, set_contact_delay, set_contact_email, set_contact_phone, set_contact_title, show, and update</p>

1 个答案:

答案 0 :(得分:0)

contacts_url映射到:controller => "some_controller", :action => "index"

您需要将操作更改为update

正确的路线是contact_path