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)
Reply
Join the discussion
Create an account Log in

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

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

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