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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:14:49+00:00 2026-05-23T21:14:49+00:00

I need some help with nested resource actions. I have three nested resources: Jobs,

  • 0

I need some help with nested resource actions. I have three nested resources: Jobs, Questions and Answers. I am currently only trying to get the edit/update method to work for the questions controller. The relationship is as so: Jobs has_many questions and Questions belong to Jobs.

I am using the edit action on the questions and am getting an error:

No route matches "/jobs/1/questions"

and I cannot figure out why.

I currently have this code as my edit and update action in my Questions controller:

def edit
 @job = Job.find(params[:job_id])
 @question = @job.questions.find(params[:id])
end

def update
  @job = Job.find(params[:job_id])
  @question = @job.questions.find(params[:id])

  if @question.update_attributes(params[:question])
    redirect_to(@question)
  end
end

Models:

class Job < ActiveRecord::Base
has_many :questions

class Question < ActiveRecord::Base
belongs_to :job

Routes:

  resources :jobs do
   resources :questions do
    resources :answers
   end
 end

The things that I don’t understand are:
a) why is it redirecting me to the questions index path, when I didn’t redirect it there, and
b) It says that is not a valid route, but if I refresh that exact URL the page loads properly.

I have tried multiple options, but I can’t figure out the solution.

Thanks for the help. Let me know if you need more info.

p.s. here is my rake routes : https://gist.github.com/1077134

  • 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-23T21:14:52+00:00Added an answer on May 23, 2026 at 9:14 pm

    So it turns out that my issue was a little more involved than I had originally thought. My database and tables were not setup properly and they were having trouble finding the proper :ids for my resources. I had to start by normalizing my tables like so:

    class CreateQuestions < ActiveRecord::Migration
    def self.up
    create_table :questions do |t|
       t.references :job
      t.text :question1
      t.text :question2
      t.text :question3
      t.text :question4
      t.text :question5
      t.text :question6
      t.text :question7
      t.text :question8
      t.text :question9
      t.text :question10
    
      t.timestamps
    end
    end
    

    This set up was repetitive and dirty and it was messing up questions controller actions. So I changed it to:

    def self.up
    create_table :questions do |t|
      t.references :job
      t.text :question
    
      t.timestamps
    end
    end
    

    and created nested_forms with loops in my jobs (the parent resource) new_form view.

    <%= form_for(@job) do |f| %>
     <%= f.label :name %><br />
     <%= f.text_field :name %>
    <%= f.fields_for :questions do |builder| %>
     <%= f.label :question, "Question" %><br \>
     <%= f.text_area :question, :rows => 10 %>
    <% end %>
    

    After doing this all of my controller methods were cleaner and the edit/update action was working properly.

    This is how I solved the issue, it may not be the best way to do so. Also, if you have anything to add or any questions about my code, just let me know and I’ll see if I can help.

    Thanks!

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

Sidebar

Related Questions

I need to add some collection routes for a nested resource. I have a
I need some help from the shell-script gurus out there. I have a .txt
I need some help calculating Pi. I am trying to write a python program
I need some help with jQuery script again :-) Just trying to play with
Hi I need some help with the following scenario in php. I have a
I am new to all the anonymous features and need some help. I have
I'm working with jQuery for the first time and need some help. I have
Im trying to convert a SQL join to LINQ. I need some help in
I need some help with a query - I'm using Firebird 2.1. I have
I need some help concerning nested attributes in models with 'has_one' relationship. Model Survey

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.