0

I wan to create a link_to tag with a conditional for example:

The below code probably doesn't work... do not try

link_to "Edit postal address", edit_postal_address_path( :condition => {:organization_id => @organization_id } )

I want to edit the postal address with the organization_id that I have in a variable. Is there a slick way of doing this or would I have to take the long way?

I hope this makes sense.

Jakcst
  • 605
  • 3
  • 8
  • 16
  • I'm not 100% sure what you're asking. Are you trying to edit the postal address record that has the `id` that is stored in that `@organization_id` variable? – Zajn Sep 28 '12 at 19:39
  • i did not understand, do you need to use the organization_id in the edit postal address method? – user1455116 Sep 28 '12 at 19:40
  • My postal address model has a column called organization_id. I want to edit the postal address where organization_id = @organization_id. – Jakcst Sep 28 '12 at 19:44
  • I gotcha now. Take a look at D3mon's answer below! – Zajn Sep 28 '12 at 19:45

1 Answers1

4
link_to "Edit postal address", edit_postal_address_path( PostalAddress.where("organization_id = ?", @organization_id)

This relationship should be each Organization has_one PostalAddress

Sully
  • 14,672
  • 5
  • 54
  • 79
  • 1
    Just wanted to add that I had better luck with this method.. PostalAddress.find(:first, :conditions => {:organization_id => @organization_id}) – Jakcst Sep 28 '12 at 20:11