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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:51:34+00:00 2026-06-11T03:51:34+00:00

I’m new to Rails and am working towards creating a hyper link in ‘

  • 0

I’m new to Rails and am working towards creating a hyper link in ‘views/admins/show.html.erb‘ that loads ‘views/residents/new.html.erb‘. In the name of clarity ‘views/admins/show.html.erb‘ and ‘views/residents/new.html.erb‘ are from separate controllers. I am stumped on finding solutions to my routing failures, and am generating the following message:

NameError in Admins#show

Showing
/Users/beracus/rails_projects/whizcharts/app/views/admins/show.html.erb
where line #11 raised:

undefined local variable or method `residents_new’ for

<#:0x000001019a2228> Extracted source (around line #11):

11:
<%= link_to ‘create a new resident’, residents_new %>

I would like to figure out how to successfully create a hyper-link in Rails that enables me to link to other views/partials whether or not they are from the same controller. Also I would like to better understand what my error message means to help prevent this in the future. Any guidance to documentation is appreciated, as well as pointing out any design rules I may be violating. I’ve searched for and found similar challenges posed to others, but due to my inexperience, I’ve not yet been able to cater those solutions to my needs.

I have tried the following.

  1. Ruby on Rails guide
  2. The low down on routes in Rails 3
  3. Rails 3 render action from another controller
  4. undefined method `companies_path’ error
  5. ruby rails – undefined local variable or method
    `new_user_session_path’

Here’s my code:

    # config/routes.rb
     Sample::Application.routes.draw do
      resources :admins do
        resources :residents
      end
      resources :sessions, only: [:new, :create, :destroy]

      root to: 'static_pages#home'

      match '/signup',    to: 'admins#new'
      match '/signin',    to: 'sessions#new'
      match '/signout',   to: 'sessions#destroy', via: :delete

      match '/help',      to: 'static_pages#help'
      match '/about',     to: 'static_pages#about'
      match '/contact',   to: 'static_pages#contact'
          .
          .
          .
      match ':controller(/:action(/:id))(.:format)'
    end


    # controllers/admins_controller.rb

    class AdminsController < ApplicationController
    before_filter :signed_in_admin, only: [:index, :edit, :update]
    before_filter :correct_admin,   only: [:edit, :update]
    before_filter :super_admin, only: :destroy

    def index
        @admins = Admin.paginate(page: params[:page]) 
    end

    def show
        @admin = Admin.find(params[:id])
    end

    def new
        @admin = Admin.new
    end

    def create
        @admin = Admin.new(params[:admin])
        if @admin.save
            sign_in @admin
            flash[:success] = "Welcome to Whizcharts!"
            redirect_to @admin
        else
            render 'new'
        end
    end

    def edit
        @admin = Admin.find(params[:id])
    end

    def update
        @admin = Admin.find(params[:id])
        if @admin.update_attributes(params[:admin])
            flash[:success] = "Profile updated"
            sign_in @admin
            redirect_to @admin
        else
            render 'edit'
        end
    end

    def destroy
        Admin.find(params[:id]).destroy
        flash[:success] = "User deleted."
        redirect_to admins_path
    end

    private

        def signed_in_admin
            unless signed_in?
            store_location
            redirect_to signin_path, notice: "Please sign in."
        end

        def correct_admin
            @admin = Admin.find(params[:id])
            redirect_to(root_path) unless current_admin?(@admin)
        end

        def super_admin
            redirect_to(root_path) unless current_admin.super?
        end
    end
end


# controllers/residents_controller.rb

class ResidentsController < ApplicationController
  def index
    @residents = Resident.paginate(page: params[:page])
  end

  def show
    @resident = Resident.find(params[:id])
  end

  def new
    @resident = Resident.new
  end

  def create
    @resident = Resident.new(params[:resident])
  end

  def edit
    @resident = Resident.find(params[:id])
  end

  def update
    @resdient = Resident.find(params[:id])
    if @resident.update_attributes(params{:resident})
        flash[:success] = "Resident's profile updated"
        sign_in @resident
        redirect_to @resident
    else
      render 'edit'
    end
  end

  def destroy
    Resident.find(params[:id]).destroy
    flash[:success] = "Resident deleted"
    redirect_to residents_path
  end

  def _form
    @residents = Resident.paginate(page: params[:page])
  end
end


# views/admins/show.html.erb

<% provide(:title, @admin.fname + " " + @admin.lname) %>
<div class="row">
    <aside class="span4">
        <section>
            <h1>
                <%= gravatar_for @admin %>
                <%= @admin.fname + " " + @admin.lname %> 
            </h1>
        </section>
        <section class="resident">
            <%= link_to 'create a new resident', residents_new %>
        </section>
    </aside>
</div>

# views/residents/new.html.erb
<% provide(:title, @admin.fname + " " + @admin.lname) %>
<div class="row">
    <aside class="span4">
        <section>
            <h1>
                <%= gravatar_for @admin %>
                <%= @admin.fname + " " + @admin.lname %> 
            </h1>
        </section>
        <section class="resident">
            <%= link_to 'create a new resident', residents_new %>
        </section>
    </aside>
</div>

# views/residents/form.html.erb 

<%= form_for(@resident) do |f| %>
    <% if @resident.error.any? %>
        <div id="error_explanation">
            <h2>
                <%= pluralize(@resident.errors.count, "error") %>
                prohibited this resident from being saved:
            </h2>
            <ul>
                <% @resident.errors.full_messages.each do |msg| %>
                <li><%= msg %></li>
                <% end %>
            </ul>
        </div>
    <% end %>

    <div class="field">
        <%= f.label :fname %><br />
        <%= f.text_field :fname %>
    </div>
    <div class="field">
        <%= f.label :lname %><br />
        <%= f.text_field :lname %>
    </div>
    <div class="field">
        <%= f.label :dob %><br />
        <%= f.text_field :dob %>
    </div>
    <div class="field">
        <%= f.radio_button :gender, 'Male' %>
        <%= f.label "gender", "Male" %>
        <br />
        <%= f.radio_button :gender, 'Female' %>
        <%= f.label "gender", "Female" %>
        <br />
        <%= f.radio_button :gender, 'Other' %>
        <%= f.label "gender", "Other" %>
        <br />
    </div>
    <div class="field">
        <%= f.label :soc %><br />
        <%= f.text_field :soc %><br />
    </div>
    <div class="field">
        <%= f.label :address %><br />
        <%= f.text_field :address %>
    </div>
    <div class="field">
        <%= f.label :city %><br />
        <%= f.text_field :city %>
    </div>
    <div class="field">
        <%= f.label :state %><br />
        <%= f.text_field :state %>
    </div>
    <div class="field">
        <%= f.label :zip %><br />
        <%= f.text_field :zip %>
    </div>
    <div class="field">
        <%= f.label :phone %><br />
        <%= f.text_field :phone %>
    </div>
    <div class="field">
        <%= f.label :doc_fname %><br />
        <%= f.text_field :doc_fname %>
    </div>
    <div class="field">
        <%= f.label :doc_lname %><br />
        <%= f.text_field :doc_lname %>
    </div>
    <div class="field">
        <%= f.label :doc_phone1 %><br />
        <%= f.text_field :doc_phone1 %>
    </div>
    <div class="field">
        <%= f.label :doc_phone2 %><br />
        <%= f.text_field :doc_phone2 %>
    </div>
    <div class="field">
        <%= f.label :doc_fax %><br />
        <%= f.text_field :doc_fax %>
    </div>
    <div class="field">
        <%= f.label :doc_email %><br />
        <%= f.text_field :doc_email %>
    </div>
    <div class="field">
        <%= f.label :guard_fname %><br />
        <%= f.text_field :guard_fname %>
    </div>
    <div class="field">
        <%= f.label :guard_lname %><br />
        <%= f.text_field :guard_lname %>
    </div>
    <div class="field">
        <%= f.label :guard_address %><br />
        <%= f.text_field :guard_address %>
    </div>
    <div class="field">
        <%= f.label :guard_city %><br />
        <%= f.text_field :guard_city %>
    </div>
    <div class="field">
        <%= f.label :guard_state %><br />
        <%= f.text_field :guard_state %>
    </div>
    <div class="field">
        <%= f.label :guard_zip %><br />
        <%= f.text_field :guard_zip %><br />
    </div>
    <div class="field">
        <%= f.label :guard_phone1 %><br />
        <%= f.text_field :guard_phone1 %>
    </div>
    <div class="field">
        <%= f.label :guard_phone2 %><br />
        <%= f.text_field :guard_phone2 %>
    </div>
    <div class="field">
        <%= f.label :guard_email %><br />
        <%= f.text_field :guard_email %>
    </div>
    <div class="actions">
        <%= f.submit %>
    </div>
    <% end %>


# rake routes 

Mac-Pro:whizcharts beracus$ rake routes
    admin_residents GET    /admins/:admin_id/residents(.:format)          residents#index
                    POST   /admins/:admin_id/residents(.:format)          residents#create
 new_admin_resident GET    /admins/:admin_id/residents/new(.:format)      residents#new
edit_admin_resident GET    /admins/:admin_id/residents/:id/edit(.:format) residents#edit
     admin_resident GET    /admins/:admin_id/residents/:id(.:format)      residents#show
                    PUT    /admins/:admin_id/residents/:id(.:format)      residents#update
                    DELETE /admins/:admin_id/residents/:id(.:format)      residents#destroy
             admins GET    /admins(.:format)                              admins#index
                    POST   /admins(.:format)                              admins#create
          new_admin GET    /admins/new(.:format)                          admins#new
         edit_admin GET    /admins/:id/edit(.:format)                     admins#edit
              admin GET    /admins/:id(.:format)                          admins#show
                    PUT    /admins/:id(.:format)                          admins#update
                    DELETE /admins/:id(.:format)                          admins#destroy
           sessions POST   /sessions(.:format)                            sessions#create
        new_session GET    /sessions/new(.:format)                        sessions#new
            session DELETE /sessions/:id(.:format)                        sessions#destroy
               root        /                                              static_pages#home
             signup        /signup(.:format)                              admins#new
             signin        /signin(.:format)                              sessions#new
            signout DELETE /signout(.:format)                             sessions#destroy
               help        /help(.:format)                                static_pages#help
              about        /about(.:format)                               static_pages#about
            contact        /contact(.:format)                             static_pages#contact
                           /admin(.:format)                               admins#index
               show        /show(.:format)                                admins#show
                new        /new(.:format)                                 admins#new
             create        /create(.:format)                              admins#create
               edit        /edit(.:format)                                admins#edit
             update        /update(.:format)                              admins#update
            destroy        /destroy(.:format)                             admins#destroy
          residents        /residents(.:format)                           residents#path
               form        /form(.:format)                                residents#form
                           /create(.:format)                              residents#create
                           /destroy(.:format)                             residents#destroy
                           /edit(.:format)                                residents#edit
              index        /index(.:format)                               residents#index
                           /new(.:format)                                 residents#new
                           /show(.:format)                                residents#show
                           /update(.:format)                              residents#update
                           /:controller(/:action(/:id))(.:format)         :controller#:action
  • 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-11T03:51:35+00:00Added an answer on June 11, 2026 at 3:51 am

    Is it really necessary to use all these match for admins and residents in config/routes.rb?

    You’ve already created resourceful routes with

    resources :admins do 
      resources :residents
    end
    

    Anyway new_admin_resident_path helper should solve your problem for nested resource.
    Or new_resident_path helper for unnested.

    <%= link_to 'Create a new resident', new_admin_resident_path %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.