Search code examples
ruby-on-railsrouteslink-torestful-url

Can I use an edit path with conditional for ruby on rails link_to?


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.


Solution

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

    This relationship should be each Organization has_one PostalAddress