0

In my application.html.erb, I have this:

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

Pay special attention the elsif current_page?... line. That's where the error is being generated.

I visit Question#Index, and I get this error in my server log (error is at the bottom):

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"}:

However, in my routes.rb I have this:

resources :jobs

And my rails/info/routes (aka web version of rake routes) has this:

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

I have this in my JobsController.rb

  def show
  end

I have restarted my server a few times, and still no dice.

Thoughts?

marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • 2
    You are missing the id parameter that is required for this route, since it is the show route for a specific job. See: http://stackoverflow.com/questions/5627958/no-routes-matches-when-using-current-page-in-rails-3 – IngoAlbers Jun 22 '16 at 06:51
  • Ahh good looking out. Ok, I will scrap this `current_page?` method then and go back to what I originally had. Thanks! – marcamillion Jun 22 '16 at 06:56

0 Answers0