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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:16:23+00:00 2026-06-14T13:16:23+00:00

So I am relatively new to Ruby on Rails and am building a project

  • 0

So I am relatively new to Ruby on Rails and am building a project management system for an independent study at my University using the language. So far I have created:

  • an an area where a user can create a multiple projects(http://i.imgur.com/pXOBg.png)
  • and in each project a user can create multple to-do lists (https://i.stack.imgur.com/H6yKb.png)
  • within each to-do list, a user can create multiple tasks which can be marked as complete/incomplete (http://i.imgur.com/DMdcN.png)

Everything’s related via foreign keys in the SQLite DB, and is working relatively fine, except that when I add a task. Although the task does get added to the to-do list, I get redirected to an incorrect URL. I created the to-do list app separate from my project management system just to see how I could create it and the redirecting and everything worked just fine, but implementing it into my project has proved somewhat troublesome.

Here is the problem that am running into: https://i.stack.imgur.com/C7ruk.jpg. The link in the URL should be http://localhost:3000/projects/2/lists/15, so the IDs are getting mixed up. What’s being displayed is http://localhost:3000/projects/15/lists/14 where 15 is the ID of the list, not the project, and 14 is the ID of the task, not the list.

I believe the problem lies within my tasks_controller.rb, which contains the following:

class TasksController < ApplicationController

  attr_accessor :completed
  before_filter :find_list
  respond_to :html, :xml, :js

  def create
    @task = @list.tasks.new(params[:task])
    if @task.save
      flash[:notice] = "Task saved"
      redirect_to project_list_url(@list)
    else
      flash[:error] = "Task could not be saved"
      redirect_to project_list_url(@list)
    end
  end

  def complete
    @task = @list.tasks.find(params[:id])
    @task.completed = true
    @task.save
    redirect_to project_list_url(@list)
  end

  def incomplete 
    @task = @list.tasks.find(params[:id])
    @task.completed = false
    @task.save
    redirect_to project_list_url(@list)
  end

  def destroy
    @task = @list.tasks.find(params[:id])
    if @task.destroy
      flash[:notice] = "Task deleted"
      redirect_to project_list_url
    else
      flash[:error] = "Could not delete task"
      redirect_to project_list_url
    end
  end

  private 

  def find_list
    @list = List.find(params[:list_id])
  end

end

I think that the problem arises on the following $link redirect_to project_list_url(@list) because I believe that it should be $link redirect_to project_list_url(@project, @list). But everytime I add:

@project = Project.find(params[:project_id])

To my code, the to-do tasks won’t move from completed to incomplete or vice versa.

Here is the code in my to-do list view:

<h3>Stuff to do</h3>
<ul>
  <% @list.tasks.incomplete.each do |task| %>
    <li><%= task.description %> <%= button_to "Complete", complete_task_path(@list.id,task.id) %></li>
  <% end %>
</ul> 

<h3>Stuff I've Done</h3>
<ul>
  <% @list.tasks.completed.each do |task| %>
    <strike><li><%= task.description %></strike> <%= button_to "Incomplete", incomplete_task_path(@list.id,task.id) %></li>
  <% end %>
</ul> 

<hr />

<%= form_for [@project, @list, @task] do |form| %>
  <p><%= form.text_field :description %> <%= form.submit %></p>

Lastly, here’s a quick look at my routes.rb:

root :to => 'home#index'

devise_for :users

resources :projects do 
  resources :messages
  resources :lists do
    resources :tasks
  end
end

match 'lists/:list_id/tasks/:id/complete' => 'tasks#complete', :as => :complete_task
match 'lists/:list_id/tasks/:id/incomplete' => 'tasks#incomplete', :as => :incomplete_task

So the IDs are mixed up in the URL, and they do this whenever I edit a list as well (although I figured if I could fix it for the tasks that I could fix it for everything).

Thanks a lot to anybody who takes a look at this and offers me help, I really appreciate all of your time. If you need a look at any other controllers, models or views (projects, lists, tasks) or anything from my project, I would be more than happy to share it.

  • 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-14T13:16:24+00:00Added an answer on June 14, 2026 at 1:16 pm

    project_list_url(@list): this routing helper takes two parameters: a project and a list. Try adding the project (or just the project id):

    redirect_to project_list_url(@list.project_id, @list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to Ruby on Rails. I'm using a particular gem my_gem in
I'm creating a basic sign up form using ruby on rails (I'm relatively new
I'm relatively new to Ruby on Rails. As of now have this working code
I’m relatively new to Ruby, Sinatra, and DataMapper, but have a question about DataMapper
I am relatively new to rails and have been working my way through the
I'm relatively new to Ruby on Rails 3 and hope to integrate Ambethia's Recaptcha
I am relatively new to ruby on rails, so this question might be easy.
I'm relatively new to Ruby on Rails and occasionally I find this convention-over-configuration stuff
I'm relatively new to Ruby and have limited time therefore I try out simple
I am new to Ruby . I have a question with respect to using

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.