How to get a slug in Ruby on Rails and use it as body class for the page?

68 Views Asked by At

I'm a noob in Ruby, and I have this project where I really need pages to have unique classes/ids. That would be very convenient for stying.

Each page on the website has a slug. Like www.site.com/page-slug

So I'm looking for a solution that would allow me to get that page slug and assign it to that page's body. Then I can just go ahead and create unique styles for that page.

I could do this with JavaScript, but I'd rather do it with Ruby on Rails if that's possible.

I haven't really tried anything yet, because I'm not qualified enough. I'm looking for general and/or specific advice. Links to tutorials and aritcles are welcome as well!

1

There are 1 best solutions below

2
Datustan On
"> This works in my case, and it may not work like this in your case. Then try something similar.