For SEO purposes, I’d like to be able to use the same HTML template in my paint#index
file to create multiple urls with different @seo_title
attributes.
For example:
My HTML index page (located on app/views/paint/index.html.erb):
<% @seo_title = "Red Paint Colors" %>
<h1> PAINT COLORS </h1>
<ul><% @paint_colors.each do |p| %>
<li><%= p.name %> - <%= p.color_family %></li>
<% end %>
</ul>
And my routes file:
get "red-paint-colors", to => "paint#index"
This makes the url: ww.mysite.com/red-paint-colors
my controller:
class PaintController < ApplicationController
def index
@paint_colors = Paints.all
end
end
Basic setup, I know…but I’d like to be able to inject a bunch of different paint colors for the url and @seo_title
so that I can have a url with that reads: www.mysite.com/blue-paint-colors with the @seo_title
of “Blue Paint Colors”.
There’s dozens of colors, is there a way I can just make a list of the colors and have a page dynamically created for each color? So basically I’d have www.mysite.com/blue-paint-colors, www.mysite.com/yellow-paint-colors, www.mysite.com/green-paint-colors, etc??
Thanks in advance!
2
Answers
I didn’t have the chance to try this code yet, but I think it could be helpful.
In your
routes.rb
file:In your
PaintController
:I would rather do it in the
show
view than in theindex
view. Then you could use friendly_id gem to customize the url. The:slug
can then be a combination of the color with the static part-paint-colors
.In terms of bulk uploading colors: I would take a look at CSV Imports.