0
votes

I am trying to namespace my site into owner / admin, and hitting a routing error. When I try to create a new Financial Report (http://localhost:3000/en/admin/financial_reports/new) I get

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

Here is my routes.rb (shortened)

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

Here is my controller 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] = 'Financial Report Uploaded Successfully' redirect_to root_url else flash[:alert] = "Financial Report not uploaded successfully" render "index" end end def yearly @financial_reports = FinancialReport.yearly end def monthly @financial_reports = FinancialReport.monthly end end

and my view

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 %>

Any idea why i'm getting this error? Thanks

1

1 Answers

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

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

Rails Namespace vs. Nested Resource