Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if part of the URL contains a certain string

Is there a way to check if part of the URL contains a certain string:

Eg. <% if current_spree_page?("/products/*") %>, where * could be anything?

like image 512
Adam Avatar asked Mar 24 '15 00:03

Adam


1 Answers

I tested, and gmacdougall's answer works, I had already found a solution though.

This is what I used to render different layouts depending on what the url is:

  url = request.path_info
  if url.include?('products')
    render :layout => 'product_layout'
  else
    render :layout => 'layout'
  end

The important thing to note is that different pages will call different methods within the controller (eg. show, index). What I did was put this code in its own method and then I am calling that method where needed.

like image 111
Adam Avatar answered Sep 19 '22 05:09

Adam