Overriding a resource route to / (root) in Rails3: not changing the path helper?

后端 未结 3 1562
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 20:39

I am quite new to Rails3, I basically created a subscribers scaffolding, I only want my app to respond to new and create actions.

相关标签:
3条回答
  • 2021-02-08 21:10

    You could do

    resources :subscribers, :path => ''
    

    and make sure that GET / is being served by your root template, e.g. by adding this to SubscribersController:

      def index
        render 'welcome/index'
      end
    

    I experimented with using a match "/" declaration to override the resource index action and map it to another controller instead but apparently a resources declaration is always fully overriding manually declared routes.

    0 讨论(0)
  • 2021-02-08 21:22

    Thank you for your answers, it helped me find the exact solution to my question:

    resources :subscribers, :only => [:new, :create], :path => '', :path_names => {:new => ''}

    Tested and working on Rails 3 :)

    0 讨论(0)
  • 2021-02-08 21:25

    For number 2 in your list, delete this line, and rewrite any _path or _url methods in your erb:

    resources :subscribers, :only => [:new, :create]
    
    0 讨论(0)
提交回复
热议问题