开发者

How do I update a :has_one value through link_to_remote?

I want to be able to change value for the :status_contact for the model Contact (has_one :status_contact

Here is the snippet with the link_to_remote:

    <%= link_to_remote "Responded - Positive",
              :url => contacts_url(@cont开发者_JS百科act, :status => 'positive response'),
              :update => "status" %>
    <span id="status"></span>

Here are relevant Model definitions for Contact.rb

  has_one :status_contact
  alias_attribute :status, :status_contact

It seems from the error that perhaps I need to create special route?

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

How do i get it so that when I click on the link_to_remote, it makes the change to the value via ajax?

Update: New Error I made the change per below:

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

I am not sure what action it is looking for in the controller. I do have an 'update' action. This is the URL that gets passed through the Firebug console:

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>


contacts_url maps to :controller => "some_controller", :action => "index"

What you need is to change the action to update

The correct route for this is contact_path

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜