路由嵌套控制器 - Rails

时间:2016-05-29 21:46:09

标签: ruby-on-rails ruby routing

我有一个名为visits的子控制器和一个名为Subscriber的超级控制器我是铁杆的新手,我现在还没有解决这个问题。我试图为访问控制器呈现一个视图我收到此错误 - 没有路由匹配[GET]" / subscribers / visits / new" - 我不确定如何将此约定发布出去?为了清楚起见,我会展示我的代码。

路线:

  devise_for :users
  resources :subscribers do
   resources :visits, shallow: true
  end

顺便说一句,这是行不通的。

控制器

  class Subscribers::VisitsController < ApplicationController
   def new
    @subscriber = Subscriber.new
   end

   def create
    @subscriber =  Subscriber.find_by_phone_number(params[:phone_number])
   if @subscriber
    @subscriber.visit += 1
    @subscriber.save
   end
   end
   end

    class SubscribersController < ApplicationController
     def index
      @subscriber = Subscriber.all
     end

     def new
      @subscriber = Subscriber.new
     end

     def create
       @subscriber = Subscriber.create(subscriber_params)
        if @subscriber.save
        flash[:success] = "Subscriber Has Been successfully Created"
        redirect_to new_subscriber_path(:subscriber)
         else
          render "new"
         end
        end

1 个答案:

答案 0 :(得分:0)

我不知道rake routes对你来说是什么样的,不知道问题是什么,所以我只是发布解决方案。

将以下内容放入config / routes.rb

get '/subscribers/visits/new', to: 'subscribers/visits#new'