Passing paramter but without GET

Hello

is there any way to pass paramters in a more proper way than I do
currently? Since it’s the easiest way I’m just passing them as GET
parameters at the moment for example:
http://localhost:3000/actions/980190963/add_date?t=2010-02-23
http://localhost:3000/actions/new?at=678542324&t=851829735&tt=Type1

I really don’t like that way of passing parameters and doesn’t look very
rails-like.

So solution I can think of so far is to turn all of these links into
forms with hidden tags but I don’t really like that either even though I
think it’s better than now.

Anyone knowing a better solution to this?

Thanks!

On 22 February 2010 13:36, Heinz S. [email protected] wrote:

So solution I can think of so far is to turn all of these links into
forms with hidden tags but I don’t really like that either even though I
think it’s better than now.

I don’t understand what you mean. Even if you use hidden fields the
url will still look as in your examples. Or are you actually talking
about what the code in your view looks like. If so then, for example,
you can just add the parameters in link_to, so for example:
link_to ‘Some Text’, :controller => ‘some_controller’, :action =>
‘some_action’, :t => ‘2010-02-23’, tt => ‘Type1’

Colin

Colin L. wrote:

I don’t understand what you mean. Even if you use hidden fields the
url will still look as in your examples. Or are you actually talking
about what the code in your view looks like. If so then, for example,
you can just add the parameters in link_to, so for example:
link_to ‘Some Text’, :controller => ‘some_controller’, :action =>
‘some_action’, :t => ‘2010-02-23’, tt => ‘Type1’

Colin

Sorry if didn’t make myself clear. I just wanna get rid of the
parameters in the URL and pass them so they’re not in the URL.

On 22 February 2010 13:36, Heinz S. [email protected] wrote:

http://localhost:3000/actions/980190963/add_date?t=2010-02-23
http://localhost:3000/actions/new?at=678542324&t=851829735&tt=

Anyone knowing a better solution to this?

You could customise some nice route mapping, to translate these into
pretty urls:

http://localhost:3000/actions/980190963/add_date/2010-02-23
http://localhost:3000/actions/new/678542324/851829735

Sorry if didn’t make myself clear. I just wanna get rid of the
parameters in the URL and pass them so they’re not in the URL.
That requires a POST request.

If you want an URL that looks something like
“actions/new/678542324/851829735/Type1”, then you could define a custom
route like “map.connect ‘:controller/:action/:id/:at/:t/:tt’”, which
would enable you to add more parameters without labeling them in the url
itself, but I am not sure how well that works with restful resources.

Thanks for the advice. Thought of it as well but isn’t there an
unwritten rule of not nesting routes too deep and stuff like that?

Heinz S. wrote:

Thanks for the advice. Thought of it as well but isn’t there an
unwritten rule of not nesting routes too deep and stuff like that?

map.connect ‘:controller/:action/:id/:at/:t/:tt’

http://localhost:3000/actions/980190963/add_date/2010-02-23
http://localhost:3000/actions/new/678542324/851829735

This is not nesting routes. It’s just mapping a URL with with some
parameters.

If you have not read this guide I’d suggest doing so. If you have then
I’d suggest re-reading it:
http://guides.rubyonrails.org/routing.html

No one?

Hi Heinz,

On Mon, 2010-02-22 at 19:38 +0100, Heinz S. wrote:

No one?

Didn’t see your prior post. Repost and maybe I can help.

Best regards,
Bill

Sorry - missed the original post.

You want to POST a parameter instead of using GET? From where?

A controller?
post { :some_action, {:login => “bob”, :password => “jones” }

From a view - just do a normal form, it defaults to post

Thanks, I read it. Makes sense :slight_smile:

Still having some trouble, routes.db:
map.connect ‘:controller/:id/:action/:action_id’

In the html file:
link_to atp.name, {:controller => ‘activities’, :id => @activity,
:action => ‘select_characters’, :action_id => atp.id }

nor

select_characters_activity_path(@activity, {:action_id => atp.id})

works. It still creates:

http://localhost:3000/activities/980190963/select_characters?action_id=291929305

URLs.

Anyone knows why? Seems fine too me.

map.connect ‘/actions/:action_id/add_date/:date’, :controller =>
‘actions’, :action => ‘add_date’

/actions/980190963/add_date/2010-02-23http://localhost:3000/actions/980190963/add_date/2010-02-23

I tried
map.connect ‘/actions/:action_id/add_date/:date’, :controller =>
‘actions’, action => ‘add_date’
instead of
map.connect ‘:controller/:id/:action/:action_id’
but that didn’t work cause that’s not what’s not working.

I need to know how the link_to has to look like so the link_to URL looks
like:
http://localhost:3000/actions/980190963/add_date/2010-02-23

No, I just want to change these URLs:
http://localhost:3000/actions/980190963/add_date?t=2010-02-23
http://localhost:3000/actions/new?at=678542324&t=851829735&tt=
into:
http://localhost:3000/actions/980190963/add_date/2010-02-23
http://localhost:3000/actions/new/678542324/851829735
for better readability.

I tried it with:
map.connect ‘:controller/:id/:action/:action_id’
link_to atp.name, {:controller => ‘activities’, :id => @activity,
:action => ‘select_characters’, :action_id => atp.id }
or
select_characters_activity_path(@activity, {:action_id => atp.id})
but I only get:
http://localhost:3000/activities/980190963/select_characters?action_id=291929305

So my question was how to create this kind of link:
http://localhost:3000/actions/980190963/add_date/2010-02-23

On Mon, Feb 22, 2010 at 3:19 PM, Heinz S. [email protected]
wrote:

I tried
map.connect ‘/actions/:action_id/add_date/:date’, :controller =>
‘actions’, action => ‘add_date’
instead of
map.connect ‘:controller/:id/:action/:action_id’
but that didn’t work cause that’s not what’s not working.

I need to know how the link_to has to look like so the link_to URL looks
like:
http://localhost:3000/actions/980190963/add_date/2010-02-23

Use a named route

map.add_date_to_action ‘/actions/:action_id/add_date/:date’,
:controller => ‘actions’, action => ‘add_date’

And then:

link_to “Add”, add_date_to_action_url(@action.id, Date.today.to_s)


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

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