0

我正在尝试将我的网站命名为所有者/管理员,并遇到路由错误。当我尝试创建一个新的财务报告 (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

这是我的控制器 app/controllers/admin/financial_reports_controller.rb

class Admin::FinancialReportsController < BaseController

def index @financial_reports = FinancialReport.all end

def new @financial_report = FinancialReport.new end

def create @financial_report = FinancialReport.new(params[:financial_report]) if @financial_report.save flash[:notice] = '财务报告上传成功' redirect_to root_url else flash[:alert] = "财务报告未上传成功" render "指数”年底结束def yearly @financial_reports = FinancialReport.yearly end defmonthly @financial_reports = FinancialReport.monthly end end

和我的看法

app/views/admin/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 %>

知道为什么我会收到此错误吗?谢谢

4

1 回答 1

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

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

Rails 命名空间与嵌套资源

于 2012-04-19T19:14:28.643 回答