ghwohg
@ghwohg

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

railsでのpathの変更の仕方

解決したいこと

railsでサイト制作をしています。

今サイトのurlが
省略...herokuapp.com
です。
これを
省略...herokuapp.com/potepan
にしたいです。

さらにそのサイト内から違うページに移動した時のurlの
herokuapp.com/products/solidus-t-shirt

herokuapp.com/potepan/products/1
に変更したいです。

products_controller.rb

class Potepan::ProductsController < ApplicationController
  def show
    @product = Spree::Product.find(params[:id])
  end
end

app/view/products/show.html.erb

<% provide(:title, @product.name) %>
<%= render 'light_section', product: @product %>

<!-- MAIN CONTENT SECTION -->
<section class="mainContent clearfix">
  <div class="container">
    <div class="row singleProduct">
      <div class="col-xs-12">
        <div class="media">
          <%= render 'media_left' %>
          <%= render 'media_body', product: @product %>
        </div>
      </div>
    </div>
    <%= render 'product_content' %>
  </div>
</section>

config/routes.rb

Rails.application.routes.draw do
  mount Spree::Core::Engine, at: '/'

  namespace :potepan do
    get '/',                        to: 'sample#index'
    get 'index',                    to: 'sample#index'
    get :product_grid_left_sidebar, to: 'sample#product_grid_left_sidebar'
    get :product_list_left_sidebar, to: 'sample#product_list_left_sidebar'
    get :single_product,            to: 'sample#single_product'
    get :cart_page,                 to: 'sample#cart_page'
    get :checkout_step_1,           to: 'sample#checkout_step_1'
    get :checkout_step_2,           to: 'sample#checkout_step_2'
    get :checkout_step_3,           to: 'sample#checkout_step_3'
    get :checkout_complete,         to: 'sample#checkout_complete'
    get :blog_left_sidebar,         to: 'sample#blog_left_sidebar'
    get :blog_right_sidebar,        to: 'sample#blog_right_sidebar'
    get :blog_single_left_sidebar,  to: 'sample#blog_single_left_sidebar'
    get :blog_single_right_sidebar, to: 'sample#blog_single_right_sidebar'
    get :about_us,                  to: 'sample#about_us'
    get :tokushoho,                 to: 'sample#tokushoho'
    get :privacy_policy,            to: 'sample#privacy_policy'

    resources :products, only: [:show]
  end
end
0

1Answer

Your answer might help someone💌