views:

43

answers:

1

I want to pass the attributes associated with two objects into a path created from a route. In this case, the _url is skip_contact_letter_url. contact_letter and letter are passed through a render partial. The clip below resides in the partial.

<%= link_to_remote "Skip Letter Remote #{contact_letter}",
        :url => skip_contact_letter_url(contact_letter, letter),
        :update => "update-area-#{contact_letter.id}-#{letter.id}" %>
<span id='update-area-<%="#{contact_letter.id}-#{letter.id}"%>'> </span>

The route I created looks like this:

  map.resources :contact_letters, :member => {:skip => :post} 

And the controller looks like this:

 def skip

    @contact_letter = ContactLetter.new(params[:all])

    @contact_letter.status = "skipped"
    @contact_letter.date_sent = Date.today
    #@contact_letter.date_created = Date.today

    if @contact_letter.save
      render :text => 'This letter was skipped!'

    end   end

When I look at the console, none of the parameters from contact_letter or letter get passed through.

As a result of the routes, this is what it looks like from rake routes:

 skip_contact_email POST   /contact_emails/:id/skip(.:format)                 {:action=>"skip", :controller=>"contact_emails"}

Added Notes:

I am thinking the route needs to be changed so I can pass :contact_id and :letter_id, but not clear:

 map.resources 'contacts/:contact_id/letters/:letter_id/skip', :controller => 'contact_letters', :action => 'skip'
A: 

First of all, probably you dont have params[:all]. In your routes you can define something like this:

<%= link_to_remote "Skip Letter Remote #{contact_letter}",
    :url => skip_contact_letter_url(
              :contact_letter=>contact_letter.attributes, 
              :letter=>letter.attributes)

Note that contact_letter.attributes produces a hash with the object attributes. In your controller you will have like:

@contact_letter = ContactLetter.new(params[:contact_letter])

Hope this helps.

dombesz
ah, I think that's the problem, let me try that, thanks!
Angela
hmm...so :contact_letter actually is passing in the collection @contacts....so the hash will be attributes of contact, not contact_letter. How do I extract those from the hash>
Angela
I get an error: skip_contact_letter_url failed to generate from {:contact_letter=>{"
Angela
I dont really understand what you like to do, could you describe me?
dombesz
what's teh difference between your way are skip_contact_letter_url(contact_letter, letter)?
Angela