Move link_to data from URL to body

43 views
Skip to first unread message

Martin Trummer

unread,
Aug 5, 2014, 3:19:41 AM8/5/14
to rubyonra...@googlegroups.com
Hi guys,

I'm having a a link_to element which sends data to the server. This is
currently encoded in the URL. Is it possible to move this URI encoded
data to the body, in order to have a clean URL?

Thank you in advance!

Kind regards,
Martin

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Aug 5, 2014, 3:40:03 AM8/5/14
to rubyonra...@googlegroups.com
On 5 August 2014 08:18, Martin Trummer <li...@ruby-forum.com> wrote:
> Hi guys,
>
> I'm having a a link_to element which sends data to the server. This is
> currently encoded in the URL. Is it possible to move this URI encoded
> data to the body, in order to have a clean URL?

If you are literally 'sending data to the server' then generally this
should be sent using a POST, so the data will not be in the url.

Colin

Martin Trummer

unread,
Aug 5, 2014, 4:13:41 AM8/5/14
to rubyonra...@googlegroups.com
I'm having the following link_to

link_to 'Close Discussion', blog_discussion_path(@blog, @note, note: {
state_transaction: :close }, only_status: true), method: :put

The parameters state_transaction and only_status are encoded within the
query. This is is what I want to hide/remove.

Colin Law wrote in post #1154239:
> If you are literally 'sending data to the server' then generally this
> should be sent using a POST, so the data will not be in the url.

You mean changing the method to method: post and add another route?

Colin Law

unread,
Aug 5, 2014, 4:19:59 AM8/5/14
to rubyonra...@googlegroups.com
On 5 August 2014 09:13, Martin Trummer <li...@ruby-forum.com> wrote:
> I'm having the following link_to
>
> link_to 'Close Discussion', blog_discussion_path(@blog, @note, note: {
> state_transaction: :close }, only_status: true), method: :put
>
> The parameters state_transaction and only_status are encoded within the
> query. This is is what I want to hide/remove.

Use a form rather than a link. You can use hidden fields to set the
parameters, with only the submit link visible if that is what you
want.

Colin

Martin Trummer

unread,
Aug 5, 2014, 4:24:51 AM8/5/14
to rubyonra...@googlegroups.com
A form is not possible, because it's going to a different controller.
That's the reason I'm using link_to

Colin Law

unread,
Aug 5, 2014, 4:41:51 AM8/5/14
to rubyonra...@googlegroups.com
On 5 August 2014 09:24, Martin Trummer <li...@ruby-forum.com> wrote:
> A form is not possible, because it's going to a different controller.
> That's the reason I'm using link_to

Please quote relevant parts of the previous message so that individual
messages make sense. This is a mailing list, not a forum, though you
may be accessing it via a forum-like interface.

You can make a form submit to any controller you like. You can
specify the controller action with form_for by using the :url option.
Or you can just use form_tag.

Colin
Reply all
Reply to author
Forward
0 new messages