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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:34:12+00:00 2026-05-13T10:34:12+00:00

I’m trying to get the hang of basic Rails routing. I have a model

  • 0

I’m trying to get the hang of basic Rails routing.
I have a model called page which I generated with a scaffold.
I have added a method called addchild which I would like to access through

'pages/addchild/:id'

So far so good. However, I want to set up a link to this method like so:

<%= link_to 'Add child page', addchild_page_path(page) %>

Passing the ID of the current page as a parameter.

When I load my index view (where the link is), I get the following message:

undefined local variable or method `addchild_page_path' for    #<ActionView::Base:0xb67797d0>

Have I misunderstood how the path/link_to method works?

My routes file looks like this:

  map.resources :pages
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

Any advice would be greatly appreciated.

Thanks.

  • 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-13T10:34:13+00:00Added an answer on May 13, 2026 at 10:34 am

    You need to add a route to it to be able to use the named path methods.

    Since you mentioned you used scaffolding, you probably have the route setup as a resource, so all that you need to do is add the method:

    map.resources :pages, :member => {:addchild => :get}
    

    Would give you an addchild_pages_path (and the actual created path would look like /pages/:id/addchild

    You then use it like this: addchild_pages_path page, don’t call the id method directly since it is not resourceful (you won’t use the to_param in the page class, which you might want to do later).

    If you really want the url to show up as /pages/addchild/:id (which I don’t recommend) you can add

    map.addchild_page "/pages/addchild/:id", :controller => :pages, :method => :addchild
    

    before the map.resources :pages row in your routes.rb, and then use the path method as above.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I am trying to render a haml file in a javascript response like so:
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.