Link_to with hidden parameters

Hi All,

Sorry if this has been asked before, I’m just looking for a pointer on
the ‘standard’ or accepted way to get around this issue, as oppose to
some ‘bodges’ that would seem workable.

Dead simple:

I have an index page for model ‘properties’ which needs a per-property
link to create a new ‘lease’. A link_to is fine for jumping to the
‘new’ page of the ‘lease’ model, however I want to pass the
property_id for the lease to the controller, without it appearing in
the url (Presuming I will thus have to POST it)

I know that I could do a javascript function or create a hidden form
but was wondering if there is a more elegant way to solve this, as it
must crop up all of the time.

Thanks in advance for any helpers with this

Paul

I know that I could do a javascript function or create a hidden form
but was wondering if there is a more elegant way to solve this, as it
must crop up all of the time.

taking those 2 out , and the uri, how will the server know what you
want?
you can map is to the uri so you dont use ?property= not you have to
tell
the server what you want.

On 31 March 2011 14:31, paulo [email protected] wrote:

the url (Presuming I will thus have to POST it)

I know that I could do a javascript function or create a hidden form
but was wondering if there is a more elegant way to solve this, as it
must crop up all of the time.

Well, really, the elegant way is to have the ID in the URL, and GET
it. It’s not great practice to use POSTs when a GET would do, simply
for comestic reasons.

Is there a particular business reason you can’t have the ID of the
property in the URL? If it’s simply that the URL doesn’t look pretty
with a querystring attached, you could make ‘leases’ a nested
resources, so the URLs could look like this:

/properties/1/leases/new

If it’s genuinely unacceptable to have the property ID in the URL,
then you will have to send it as form data in a POST, yes. If you want
to avoid JavaScript, but still have the element look like a link
rather than a form submit button, it’s possible to style buttons as
links:

http://natbat.net/2009/Jun/10/styling-buttons-as-links/

but this is starting to look like a hacky solution to a non-problem.
Can you elaborate more on what you’re trying to achieve?

Chris

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs