RubyRedGrapefruit
RubyRedGrapefruit

Reputation: 12224

How can I strip request values out of my Rails url?

In my Rails 3 application, I list many items on the homepage. Some of them are obscure, and I would like to limit my list to only popular items unless the user clicks a specific link that basically "zeroes out" the limiter.

What I have now works, but when the user chooses to "Show all items", I end up with a ugly url:

http://myapp.com/?limiter=0

Is there any way that I can strip that out so that the user does not see the ugly attribute at the end of the url?

Upvotes: 0

Views: 156

Answers (2)

aceofspades
aceofspades

Reputation: 7586

No, don't use POST. POST is only supposed to be used when you are making a state change on the server. Use an AJAX GET if you really need to do this.

Better yet, get used to seeing GET parameters like this. It's normal. And, it's like that for a reason: it allows bookmarking a resource, including whatever settings are needed to reproduce the request later.

Read up on REST. Learn it. Live it. Love it.

Upvotes: 1

Doug R
Doug R

Reputation: 5779

There's a number of approaches you could take. Probably the most obvious one is to have a separate page for your show_all. It sounds like you're trying to do too much with your homepage.

If you must have these on the homepage, and your link is also on the homepage, you could use an ajax call to load up your items without having to redirect to that url.

Finally I suppose you could try making a route just for this situation. I don't really have any experience with Rails3 routes, though, so I can't suggest any syntax.

Really, though, this smells like an application design problem, not a technical problem. I strongly encourage you to rethink how you are trying to do this. This doesn't sound like a feature that is appropriate to put on your homepage. Make a separate show_all action.

Upvotes: 0

Related Questions