Ruby on Rails Wednesday, January 24, 2018

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


On Sunday, October 15, 2017 at 12:50:08 PM UTC-5, Ben Edwards wrote:
PS I also tried

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

On Sunday, October 15, 2017 at 6:49:10 PM UTC+1, Ben Edwards wrote:
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"





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f6ded599-ba62-492c-bacf-cd2118064cd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment