Turning URL varables into URLs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Turning URL varables into URLs

Ben Edwards
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.


 

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/797df844-344c-4445-904e-1732687a4199%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

Hassan Schroeder-2
On Sun, Oct 15, 2017 at 6:39 AM, Ben Edwards <[hidden email]> wrote:

> 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.

At the top of config/routes.rb --

  # For details on the DSL available within this file, see
http://guides.rubyonrails.org/routing.html

HTH,
--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yA6ZHdB9-P8BKxBsq7hvp7Vqm1V4z_mJ0jN0EH40e2_mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

Ben Edwards
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/65bc12ae-50da-4fb5-b111-0c19a9a49c30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

Ben Edwards
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 (<a href="http://domain.tld" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGvbWg9vYbjaexgx3n4gQbMZsudaQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGvbWg9vYbjaexgx3n4gQbMZsudaQ&#39;;return true;">http://domain.tld) and want to pass cost as a variable (<a href="http://domain.tld?cost=cheapevents" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%3Fcost%3Dcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFWzsqJx5wI0BCK7oBN8QkU9JxXHQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%3Fcost%3Dcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFWzsqJx5wI0BCK7oBN8QkU9JxXHQ&#39;;return true;">http://domain.tld?cost=cheapevents = <a href="http://domain.tld/cheapevents" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;">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 <a href="http://domain.tld/cheapevents" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;">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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c732fd97-440f-4e19-922f-4f8182d3d6b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

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

On Sunday, October 15, 2017 at 6:50:08 PM UTC+1, 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 (<a href="http://domain.tld" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGvbWg9vYbjaexgx3n4gQbMZsudaQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGvbWg9vYbjaexgx3n4gQbMZsudaQ&#39;;return true;">http://domain.tld) and want to pass cost as a variable (<a href="http://domain.tld?cost=cheapevents" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%3Fcost%3Dcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFWzsqJx5wI0BCK7oBN8QkU9JxXHQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%3Fcost%3Dcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFWzsqJx5wI0BCK7oBN8QkU9JxXHQ&#39;;return true;">http://domain.tld?cost=cheapevents = <a href="http://domain.tld/cheapevents" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;">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 <a href="http://domain.tld/cheapevents" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdomain.tld%2Fcheapevents\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEodslvdXljzjQTxwkKN5cGev4d9w&#39;;return true;">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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d07b042a-de66-4ef0-b1c0-419eabe47baa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

Hassan Schroeder-2
In reply to this post by Ben Edwards
On Sun, Oct 15, 2017 at 10:49 AM, Ben Edwards <[hidden email]> wrote:
> Great, thanks, almost there.  Mine is slightly different as its not based on
> CRUD, its a ruby view based on a SQL view.

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

--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yCwEmH12Lc0yJqhuUR75P3chQMUMR%3DXRDb01Wmf_0h_8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

Aboobacker M K
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

On Mon, Oct 16, 2017 at 12:58 AM, Hassan Schroeder <[hidden email]> wrote:
On Sun, Oct 15, 2017 at 10:49 AM, Ben Edwards <[hidden email]> wrote:
> Great, thanks, almost there.  Mine is slightly different as its not based on
> CRUD, its a ruby view based on a SQL view.

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

--
Hassan Schroeder ------------------------ [hidden email]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yCwEmH12Lc0yJqhuUR75P3chQMUMR%3DXRDb01Wmf_0h_8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards
Aboobacker MK

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAP3AYfaTspBec2F%3DatuXkVTit7zx3%3Dx0%2B1jc0sFm8ALRBrtTKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Turning URL varables into URLs

Mugurel Chirica
You can try something like this if the requirements match:

  match "/*path", to: redirect { |params, request|
    # Add your logic here or delegate the work to a specific class

    # Proof of concept
    slug = 'jazz' # You get the slug from the params
    price_category = true # You deduce if the slug matches any of your tags
 
    if price_category
      "/#{slug}?price=cheap"
    else
      slug
    end

  }, via: :all

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL37D8F36mDnbzEHfW4P4_9aLaKP12PJLJRkC3nNn__t%3DHu8XA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.