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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:56:41+00:00 2026-05-23T08:56:41+00:00

I am getting the error Can’t find Goal with an ID but I am

  • 0

I am getting the error “Can’t find Goal with an ID” but I am not sure where I am going wrong with the code

The models are as follows:

A Goal has_many Tasks 
A Task belongs_to Goal

The create Task is as follows:

routes.rb is:

resources :goals, :only => [:create, :destroy, :show, :index]
resources :tasks, :only => [:create, :destroy, :show, :index]

goals_controller.rb#show is:

def show
     @goal = Goal.find(params[:id])
     @tasks = @goal.tasks
     @task = Task.new if signed_in?      
end

tasks_controller.rb#create is:

def create
  **@goal = Goal.find(params[:id])** 
  @task  = @goal.tasks.build(params[:task])
  if @task.save
    flash[:success] = "Task created!"
    redirect_to goal_path(@task.goal.id)
  else
    render home_path
  end
end

The line in bold is where the error is occurring. I have noticed the following:

   @goal = Goal.find(params[:goal_id]) does not work either
   @goal = Goal.find(34) works, and so do other integers I enter here

I am not sure what the issue is, as I’ve followed the same process which has worked for me previously but I’ve done something wrong this time.

I should also state the the tasks form is on the goal#show page.

  • 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-23T08:56:41+00:00Added an answer on May 23, 2026 at 8:56 am

    I have found the solution to this. I needed a hidden field in the form to pass the id through to the create method in the tasks controller.

    <%= hidden_field_tag :goal_id, @goal.id %>
    

    Hope this can help someone else too!

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

Sidebar

Related Questions

hi im new to c# and was trying to code but getting error can
Not sure why I'm getting this error and can't figure it out? The cycle
Why am I getting the following error in my code? Fatal error: Can't use
my app is getting force close randomly. And every time error can not be
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
Possible Duplicate: pthread Function from a Class I am getting an error (Can not
All the Perl dependencies for it are met but I'm getting this error: Can't
Seem to be getting an error but can't figure out how to drill down
In my application I am getting this error: You can only have one <head
I am getting the error: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server

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.