Turning URL varables into URLs

OK, so I have a homepage and want the user to be able to select a link that goes back to it with a varable set. Example here is the listings site lists all events regardless of price and I want users to be able to list events under £5. So I have a link https://eventpuddle.com?price=cheap. This is fine but for SEO reasons I want to have the URL something like https://eventpuddle.com/cheapevents. Obviesly I could create another view but there are all sorts of things I will ultimatly want ot do this for. https://eventpuddle.com/jazz, https://eventpuddle.com/pucn, https://eventpuddle.com/art… i would end up with LOTS of views and have to do code changes for eatch (see below). I came across something years ago (I think in PHP) where URLs got unpacked into varables in the background. So https://eventpuddle.com/**price**/**cheapevents** was mapped in the background and created a varable price with a value cheapevents.

This will also be usefull for listing events for a certain venue, whitch I have lots. Dont want to create a view for eatch venue as there are lots and I dont want to have to code stuff if I add venues, I simply add a row in the database for the new venue. The kind of URLs I would be looking for is https://eventpuddle.com/venue/old-market-assembly or https://eventpuddle.com/venue/canteen.

Wondering if there is a way of doing this in rails or another way of handeling the same type of thing.

At the top of config/routes.rb --

  # For details on the DSL available within this file, see

HTH,

Great, thanks, almost there. Mine is slightly different as its not based on CRUD, its a ruby view based on a SQL view. So

get ``'/patients/:id'``, to: ``'patients#show'

Is not quite what I need. If I have this view as root view (http://domain.tld) and want to pass cost as a variable (http://domain.tld?cost=cheapevents = http://domain.tld/cheapevents). Its the site root

currently I have

root 'upcoming_events#index'
**get** 'upcoming_events/index'


I tried

**get** 'upcoming_events/index:cost', to: 'upcoming_events#index'

And it works for root but if I try **http://domain.tld/cheapevents** I get

No route matches [GET] “/cheapevents”


PS I also tried

get 'upcoming_events/cost', to: 'upcoming_events#index'

Aslo http://localhost:3000/upcoming_events/cost works but not http://localhost:3000/upcoming_events/cost/cheapevents.

Irrelevant. You can use any parameter and controller method names you choose.

You can use something like this

get ‘venue/:name:’, to: ‘venues#show’

class VenueController

def show

render the view by checking params[:name]

end

end

Check the above linked routing guide for more details

You can try something like this if the requirements match:

  match "/*path", to: redirect { |params, request|

I don’t know why you’re still trying /cheapevents when you haven’t defined it at all.

Not best practices really, but try something like:

get ‘events/:cost’, to: ‘upcoming_events#index’

and then in your controller, respond based on things like:

if params[:cost] == “cheap”

@events = Events.where(“price < 5”)

end

So you can then navigate to url.name/events/cheap