RoR链接到routes.rb中的特定控制器

时间:2015-03-30 11:51:02

标签: ruby-on-rails ruby

我使用Ruby 2.0和Rails 4.2.0。我无法在_form.html.erb中为simple_form_for创建链接。我的代码: routes.eb

Rails.application.routes.draw do
    namespace :admin, path: 'uceadmin' do
        root :to => 'dashboard#index'
        namespace :newsletter, path: 'newsletter' do
          resources :lists, controller: 'newsletter_lists' do
            resources :subscribers, controller: 'newsletter_subscribers'
          end
        end
    end
end

应用\视图\管理员\ newsletter_subscribers_form.html.erb

<div class="row">
  <%= simple_form_for([:admin, :newsletter, @list, @newsletter_subscriber]) do |f| %>

rake routes:

enter image description here

我的结果是:

undefined method `admin_newsletter_newsletter_list_newsletter_subscribers_path' for #<#<Class:0xd1d5af0>:0xdc2a7b8>

1 个答案:

答案 0 :(得分:1)

我猜您应该使用:url选项传递用于提交的URL。在你的情况下,我可以看到admin_newsletter_list_subscribers_path。

<%= simple_form_for @newsletter_subscriber, url: admin_newsletter_list_subscribers_path(@list) do |f| %>