命名空间路由文件提供路由错误

时间:2012-04-19 19:09:09

标签: ruby-on-rails rails-routing

我正在尝试将我的网站命名为owner / admin,并遇到路由错误。当我尝试创建新的财务报告时(http:// localhost:3000 / en / admin / financial_reports / new) 我得到了

No route matches {:controller=>"financial_reports", :format=>nil}

这是我的routes.rb(缩短)

scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
 root :to => 'sites#index'
 get "logout" => "sessions#destroy", :as => "logout"
 get "login" => "sessions#new", as: "login"
namespace :admin do
    root :to => "base#index"
    resources :financial_reports do
      collection do
        get :monthly
        get :yearly
      end
    end
  end
namespace :owner do
    root :to => "base#index"
  end
match "*path", to: "sites#not_found" # handles /en/fake/path/whatever
end
root to: redirect("/#{I18n.default_locale}") # handles /
match '*path', to: redirect("/#{I18n.default_locale}/%{path}")
end

这是我的控制器 应用程序/控制器/管理/ financial_reports_controller.rb

class Admin::FinancialReportsController < BaseController

def index   @financial_reports = FinancialReport.all 端

def new   @financial_report = FinancialReport.new 端

def创建   @financial_report = FinancialReport.new(params [:financial_report])     if @ financial_report.save       flash [:notice] ='财务报告成功上传'       redirect_to root_url     其他       flash [:alert] =“财务报告未成功上传”       渲染“索引”     结束   结束   每年一次     @financial_reports = FinancialReport.yearly   结束   def每月     @financial_reports = FinancialReport.monthly   结束 端

和我的观点

应用程序/视图/管理/ financial_reports / new.html.erb

<%= form_for(@financial_report) do |f| %>
<p>
  <%= f.label(:report_type) %> <br>
  <%= f.radio_button :report_type, "Monthly" %> Monthly |
  <%= f.radio_button :report_type, "Yearly" %> Yearly
</p>
<p>
  <%= f.file_field :file %>
</p>
<p>
  <%= f.submit "Upload Monthly Record" %>  
</p>
<% end %>

我知道为什么会收到这个错误?感谢

1 个答案:

答案 0 :(得分:1)

<%= form_for[:admin, @financial_report] do |f| %>
........................
.............
........

http://guides.rubyonrails.org/routing.html

Rails Namespace vs. Nested Resource