Is there a way to add custom pages (the usual way:...
# support
g
Is there a way to add custom pages (the usual way: controller, model, views, routes), without being limited to the static content gem (https://github.com/solidusio-contrib/solidus_static_content)? Does anyone have a working formula for that? Thank you 😊
j
You can just add them as you would add new controllers/views/routes to any Rails application, except you likely want to add them to the "Spree" routes in your routes.rb.
You'll likely want to inherit from
Spree::StoreController
for them as well.
g
Thank you so much @Jared Norman - will try right away!
I append the routes ---
Copy code
Spree::Core::Engine.routes.prepend do

  match 'cookie-policy', to: 'legal_pages#cookie_policy', via: :get
  match 'privacy-policy', to: 'legal_pages#privacy_policy', via: :get
  match 'terms-and-conditions', to: 'legal_pages#terms_and_conditions', as: 'terms_and_conditions', via: :get
  match 'shipping-policy', to: 'legal_pages#shipping_policy', as: 'shipping_policy', via: :get

  match 'contact-us', to: 'static_pages#about_us', as: 'about_us', via: :get
  match 'faqs', to: 'static_pages#faqs', as: 'faqs', via: :get
end
Add controllers
Copy code
class Spree::LegalPagesController < Spree::StoreController
  def cookie_policy

  end

  def privacy_policy

  end

  def shipping_policy

  end

  def terms_and_conditions

  end
end
They routes don't show up running "rails routes"
@Jared Norman do you know what I am doing wrong here by any chance?
j
that all looks correct, though you don't need to use
match
, you can just use the
get
helper,
get "cookie-policy", to: "legal_pages#cookie_policy"
etc.
the routes are in
config/routes.rb
?
g
Yes they are
j
I'm not sure why they wouldn't be showing up then.
If the routes are getting loaded correctly (even if the controller doesn't exist) they should show up in
rails routes
g
It's odd, I am going to run a few more tests and see if I hit any useful info that may solve the problem
I tried this in so many different ways ..
It's just not working
Copy code
Rails.application.routes.draw do

  Spree::Core::Engine.routes.prepend do
    get 'cookie-policy', to: 'legal_pages#cookie_policy'
    get 'privacy-policy', to: 'legal_pages#privacy_policy'
    get 'terms-and-conditions', to: 'legal_pages#terms_and_conditions', as: 'terms_and_conditions'
    get 'shipping-policy', to: 'legal_pages#shipping_policy', as: 'shipping_policy'

    get 'contact-us', to: 'static_pages#about_us', as: 'about_us'
    get 'faqs', to: 'static_pages#faqs', as: 'faqs'
  end


  # This line mounts Solidus's routes at the root of your application.
  # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
  # If you would like to change where this engine is mounted, simply change the :at option to something different.
  #
  # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
  mount Spree::Core::Engine, at: '/'

  # For details on the DSL available within this file, see <https://guides.rubyonrails.org/routing.html>
end
I prepend the the routes before mounting them. So theoretically everything should be find.
*fine
As state I also do not make use of the :as option
I don't get it
Also if I remove the mount ... and add routes (without prepending, they are displayed in rails routes
Once I add the mount Spree:Core:Engine, at: '/'
I can not add any custom routes anylonger
prepending or conventional
j
This should not be inside of the
Rails.application.routes.draw
block:
move it after it
g
Hi, I did move it after now 🙂
Apologies for the slow response
What solved the issue was everything you said AND
Copy code
Spree::Core::Engine.routes.append do
  get 'cookie-policy', to: 'legal_pages#cookie_policy'
  get 'privacy-policy', to: 'legal_pages#privacy_policy'
  get 'terms-and-conditions', to: 'legal_pages#terms_and_conditions'
  get 'shipping-policy', to: 'legal_pages#shipping_policy'

  get 'contact-us', to: 'static_pages#about_us'
  get 'faqs', to: 'static_pages#faqs'
end
APPEND instead of PREPEND
Why? Who knows ...
+ If you have Solidus Static Pages Gem (https://github.com/solidusio-contrib/solidus_static_content) installed, this may cause issues too. I had to remove it to make the above work.
Thank you again @Jared Norman for your support and nudging me into the right direction! This was super helpful 😄