Ruby on Rails Thursday, March 31, 2011

On 31 March 2011 14:31, paulo <paul.a.taylor84@gmail.com> wrote:
> 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.

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment