views:

16

answers:

1

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(@contact, :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>
A: 

Hi Angela,

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

Sam
hi, so if I use contact_path instead of contacts_url, I'm good to go?
Angela
yeah. Remember, 1st get it going with plain HTML, then add JavaScript. This is for two reasons: 1) it's unobtrusive, 2) it's easier to implement in this order.
Sam
Still getting an error see above....
Angela
I should have asked this first: are you trying to update the status with this link? Because it's better to use button_to which also has button_to_remote. This way you don't have to change the controller at all. Let me know if that is the case.
Sam
yes, I am trying to change the status with the link....could you explain button_to? BTW, I have changed the associations so that contacts belongs_to :status_contact and status_contact hmmm...status_contact should only have three potential values or some set of values, so should it be has_many conatcts?
Angela
Button_to is like link_to but works like a form; which I suggest because forms are a better way to update data; Angela... I'm not sure what :status_contact is and why you have an alias_attribute so I just don't know what your trying to do :(
Sam
I am trying from the link to send a javascript to update the associated value...I had it working before but made some changes and now canot figure out the problem
Angela