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 3630808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:19:00+00:00 2026-05-19T00:19:00+00:00

I am playing with custom view and routes. I think that I have everything

  • 0

I am playing with custom view and routes. I think that I have everything right but obviously not. Essentially I tried to copy the show method and show.html.erb but for some reason it will not work.

My controller

    class fatherController < ApplicationController
      def show
        @father = Father.find(params[:id])

        respond_to do |format|
         format.html # show.html.erb
         format.xml  { render :xml => @father }
        end
      end

      def ofmine
        @father = Father.find(params[:id])

        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml => @father }
        end
      end
   end

My routes.rb

Parent::Application.routes.draw do
  resources :fathers do
     resources :kids
  end 

  match 'hospitals/:id/ofmine' => 'father#show2'
end

when I go to

127.0.0.1:/father/1

it works fine but when I try to go to

127.0.0.1:/father/1/ofmine

it gives the following error. It doesn’t matter what the variable/method that is called; it occurs at the first one to be displayed. Both show.html.erb and show2.html.erb are the exact same files

My Error from webserver commandline

> Processing by fathersController#show2
> as HTML   Parameters: {"id"=>"1"}
> Rendered fathers/show2.html.erb within
> layouts/application (31.6ms) Completed
> in 37ms
> 
> ActionView::Template::Error (undefined
> method `name' for nil:NilClass):
>     4:         <td>Name</td><td></td>
>     5:     </tr>
>     6:     <tr>
>     7:  <td><%= @father.name %></td><td></td>
>     8:     </tr>
>     9:     <tr>
>     10:  <td>City</td><td>State</td>   app/views/fathers/show2.html.erb:7:in
> `_app_views_fatherss_show__html_erb___709193087__616989688_0'

Error as displayed on actual page

NoMethodError in Fathers#show2

Showing
/var/ruby/chs/app/views/fathers/show2.html.erb
where line #7 raised:

undefined method `name’ for
nil:NilClass

Extracted source (around line #7):

4: Name 5:
6: 7: <%=
@father.name %> 8:
9: 10:
CityState

If anyone could tell me what in the world I am doing wrong I would appreciate it greatly.

Here is a copy of my rake routes

     father_ofmine      /fathers/:father_id/ofmine(.:format)               {:action=>"show2", :controller=>"fathers"}
     father_kids GET    /fathers/:father_id/kids(.:format)          {:action=>"index", :controller=>"kids"}
                 POST   /fathers/:father_id/kids(.:format)          {:action=>"create", :controller=>"kids"}
  new_father_kid GET    /fathers/:father_id/kids/new(.:format)      {:action=>"new", :controller=>"kids"}
 edit_father_kid GET    /fathers/:father_id/kids/:id/edit(.:format) {:action=>"edit", :controller=>"kids"}
      father_kid GET    /fathers/:father_id/kids/:id(.:format)      {:action=>"show", :controller=>"kids"}
                 PUT    /fathers/:father_id/kids/:id(.:format)      {:action=>"update", :controller=>"kids"}
                 DELETE /fathers/:father_id/kids/:id(.:format)      {:action=>"destroy", :controller=>"kids"}
         fathers GET    /fathers(.:format)                                     {:action=>"index", :controller=>"fathers"}
                 POST   /fathers(.:format)                                     {:action=>"create", :controller=>"fathers"}
      new_father GET    /fathers/new(.:format)                                 {:action=>"new", :controller=>"fathers"}
     edit_father GET    /fathers/:id/edit(.:format)                            {:action=>"edit", :controller=>"fathers"}
          father GET    /fathers/:id(.:format)                                 {:action=>"show", :controller=>"fathers"}
                 PUT    /fathers/:id(.:format)                                 {:action=>"update", :controller=>"fathers"}
                 DELETE /fathers/:id(.:format)                                 {:action=>"destroy", :controller=>"fathers"}
  • 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-05-19T00:19:01+00:00Added an answer on May 19, 2026 at 12:19 am

    Routes are taken into account according to their order of appearance in your routes file.

    I guess 127.0.0.1:/father/1/ofmine is interpreted as part of resources :fathers

    Put match 'hospitals/:id/ofmine' => 'father#show2' at the top of your routes.rb to try

    EDIT 1:

    I guess, you made a mistake:

    # instead of match 'hospitals/:id/ofmine' => 'father#show2' 
    match 'father/:id/ofmine' => 'father#show2'
    

    And to have a cleaner file, I’d do:

    Parent::Application.routes.draw do
      resources :fathers do
        match '/ofmine' => 'father#show2'
        resources :kids
      end 
    end
    

    EDIT 2:

    Do you have a show2 method in your controller which gets the variable?

    I’m thinking, you’re assuming the current ofmine method handles the situation which is wrong

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

Sidebar

Related Questions

I have a custom view being dynamically inserted and the onDraw is not being
I have a Cocoa application that captures keypresses through a custom view in the
I have created a custom view that contains a UIPickerView and a UITableViewCell to
I have been playing with the Command Window in Visual Studio (View->Other Windows->Command Window).
While playing around with the emulator, I noticed that when trying to view a
I have an app that has a custom background for a UITableView . Up
I'm playing around with drawing in iOS apps. I have a class that is
I need to have a custom view controller with the same functionality as the
Hey everyone I'm not a professional coder by any stretch, but I've been playing
I'm playing around with 2D drawing within a custom view. So far I've got

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.