Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:08:01+00:00 2026-06-03T01:08:01+00:00

Here is my routes file: resources :locations do resources :comments end and the controllers:

  • 0

Here is my routes file:

  resources :locations do
    resources :comments
  end

and the controllers:

    class CommentsController < InheritedResources::Base

      def index
        @commentable = find_commentable
        @comments = @commentable.comments.where(:company_id => session[:company_id])
      end

      def show
    @comment = Comment.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @comment }
    end
  end

      def new

        @comment = Comment.new

        respond_to do |format|
          format.html # new.html.erb
          format.json { render json: @comment }
        end
      end

      def create
        @commentable = find_commentable
        @comment = @commentable.comments.build(params[:comment])
        @comment.user_id = session[:user_id]
        @comment.company_id = session[:company_id]
        if @comment.save
          flash[:notice] = "Successfully created comment."
          redirect_to :id => nil
        else
          render :action => 'new'
        end
      end

      private

      def find_commentable
        params.each do |name, value|
          if name =~ /(.+)_id$/
            return $1.classify.constantize.find(value)
          end
        end
        nil
      end

    end

and rake routes:

    location_comments GET        /locations/:location_id/comments(.:format)          comments#index
                       POST       /locations/:location_id/comments(.:format)          comments#create
  new_location_comment GET        /locations/:location_id/comments/new(.:format)      comments#new
 edit_location_comment GET        /locations/:location_id/comments/:id/edit(.:format) comments#edit
      location_comment GET        /locations/:location_id/comments/:id(.:format)      comments#show
                       PUT        /locations/:location_id/comments/:id(.:format)      comments#update
                       DELETE     /locations/:location_id/comments/:id(.:format)      comments#destroy
             locations GET        /locations(.:format)                                locations#index
                       POST       /locations(.:format)                                locations#create
          new_location GET        /locations/new(.:format)                            locations#new
         edit_location GET        /locations/:id/edit(.:format)                       locations#edit
              location GET        /locations/:id(.:format)                            locations#show
                       PUT        /locations/:id(.:format)                            locations#update
                       DELETE     /locations/:id(.:format)                            locations#destroy

It’s a bit ugly (more details here: Polymorphic Comments with Ancestry Problems) given that the location <=> comment association is polymorphic.

/locations/1/comments/ loads as does /locations/1/comments/1 but /locations/1/comments/new throws a routing error No route matches {:action=>"show", :controller=>"locations"}.

My logs are showing:

Started GET "/locations/100041506421W500/comments/new" for 127.0.0.1 at 2012-04-29 00:37:43 -0600
Processing by CommentsController#new as HTML
  Parameters: {"location_id"=>"100041506421W500"}
  Rendered comments/_form.html.erb (2.4ms)
  Rendered comments/new.html.erb within layouts/application (3.9ms)
Completed 500 Internal Server Error in 25ms

ActionController::RoutingError (No route matches {:action=>"show", :controller=>"locations"}):
  app/views/comments/_form.html.erb:1:in `_app_views_comments__form_html_erb__3729217817518084843_70306885927480'
  app/views/comments/new.html.erb:3:in `_app_views_comments_new_html_erb___4071030466810932409_70306918426640'
  app/controllers/comments_controller.rb:19:in `new'


  Rendered /Users/dan/.rvm/gems/ruby-1.9.3-p0@global/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.9ms)

It looks like its rendering the form and then somewhere the 500 error crops up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:08:03+00:00Added an answer on June 3, 2026 at 1:08 am

    Somewhere in the new view you’ve got a broken link to location_path, which translates to {controller: ‘location’, action: ‘show’}, which is an invalid route (it needs a location ID).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST resource called Greetings. Here is my routes file: resources :greetings
I have the following in my routes file: resources :timelogs do member do post
I have this code in my routes.db file: resources :users do member do get
This is in my routes.rb file: resources :orders do member do get 'confirm' get
Here is my route definition in the bootstrap file: $router = $this->frontController->getRouter(); $route =
Here is my model: class Company(models.Model): id = models.AutoField(primary_key=True); name = models.CharField(max_length=100); address =
Here's the code I'm using to download a file var S3_KEY = 'xxxxxx'; var
I can't figure out how to get the following routes. Here's an extract from
I'm writing a plugin that adds a class method to ActionController::Base , so in
I have this devise routes in routes.rb file: app::Application.routes.draw do scope :locale, locale: /#{I18n.available_locales.join(|)}/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.