为什么这是current_page?打电话给我一条存在路线的无路线错误?

时间:2016-06-22 06:41:00

标签: ruby-on-rails ruby-on-rails-5 actioncontroller

在我的application.html.erb中,我有这个:

      <% if current_page?(controller: "questions", action: "index") || current_page?(controller: "jobs", action: "index") %>
        <%= "This is the IF for #{controller_name} and #{controller.action_name}" %>
            <%= yield %>
      <% elsif current_page?(controller: "jobs", action: "show") %>
        <%= "This is the ELSIF for #{controller_name} and #{controller.action_name}" %>
          <div class="wrapper wrapper-content article">
            <%= yield %>
          </div>
      <% else %>
      <% end %>

特别注意elsif current_page?...行。这就是产生错误的地方。

我访问Question#Index,我在服务器日志中收到此错误(错误位于底部):

Started GET "/" for 127.0.0.1 at 2016-06-22 01:25:57 -0500
  ActiveRecord::SchemaMigration Load (0.9ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by QuestionsController#index as HTML
  Rendering questions/index.html.erb within layouts/application
  Rendered shared/_main_page_heading.html.erb (0.4ms)
  Question Load (4.0ms)  SELECT "questions".* FROM "questions" ORDER BY "questions"."created_at" DESC
  #
  # truncated for brevity
  #
  Rendered questions/index.html.erb within layouts/application (680.3ms)
  Rendered shared/_navbar.html.erb (2.4ms)
Completed 500 Internal Server Error in 1474ms (ActiveRecord: 63.4ms)


DEPRECATION WARNING: #original_exception is deprecated. Use #cause instead. (called from initialize at /.rvm/gems/ruby-2.3.0@myapp/gems/better_errors-2.1.1/lib/better_errors/raised_exception.rb:7)
DEPRECATION WARNING: #original_exception is deprecated. Use #cause instead. (called from initialize at /.rvm/gems/ruby-2.3.0@myapp/gems/better_errors-2.1.1/lib/better_errors/raised_exception.rb:8)

ActionController::UrlGenerationError - No route matches {:action=>"show", :controller=>"jobs"}:

然而,在我的routes.rb我有这个:

resources :jobs

我的rails/info/routes(又名rake routes的网络版)就是这样:

jobs_path   GET /jobs(.:format) jobs#index    
           POST /jobs(.:format) jobs#create
new_job_path GET /jobs/new(.:format) jobs#new 
edit_job_path GET /jobs/:id/edit(.:format) jobs#edit
job_path    GET /jobs/:id(.:format) jobs#show
          PATCH /jobs/:id(.:format) jobs#update
          PUT   /jobs/:id(.:format) jobs#update
         DELETE /jobs/:id(.:format) jobs#destroy

我在JobsController.rb

中有这个
  def show
  end

我已经重启了我的服务器几次,但仍然没有骰子。

思想?

0 个答案:

没有答案