Routes with Dash `-` Instead of Underscore `_` in Ruby on Rails

前端 未结 4 1060
别那么骄傲
别那么骄傲 2020-12-04 18:33

I want my urls to use dash - instead of underscore _ as word separators. For example controller/my-action instead of controller/

4条回答
  •  渐次进展
    2020-12-04 19:24

    if you use underscores in a controller and view file then just use dashes in your routes file, and it will work..

    get 'blog/example-text' this is my route for this controller

    def example_text end <-- this is my controller

    and example_text.html.erb is the file

    and this is the actual link site.com/blog/example-text

    i figured this is works for me, and it's more effective than underscores SEO wise

提交回复
热议问题