All threads / How do I have a root route without an action parameter in the URL?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I have a root route without an action parameter in the URL?

Peter vande Put asked in Rails

My system is using a post model with friendly_id so the calls are /name_of_the_post and this works great.
The initial home page is also a post so in routes.rb I have

    root 'home#index'
        get ':slug', to: 'posts#show_post', as: 'show_post'

    ```
    My HomeController has the following index action
    ```
        def index
        redirect_to '/home'
    end
    ```
    The PostsController will pick up home slug and show the post, however my URL is now localhost:3000/home and I want it to be 
    localhost:3000/

    How can I achieve this stripping the home slug (only for home)
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 52,887+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.