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

  • Home
  • SEARCH
  • 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 8950697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:29:56+00:00 2026-06-15T13:29:56+00:00

I’ve defined nested resources in the /config/routes.rb resources :goals do resources :goal_entries end Models

  • 0

I’ve defined nested resources in the /config/routes.rb

  resources :goals do
    resources :goal_entries
  end

Models for Goal:

class Goal < ActiveRecord::Base
  attr_accessible :code, :description, :from_date, :to_date
  validates_uniqueness_of :code
  validates_presence_of :code
  has_many :goal_entries, :primary_key => "code", :foreign_key => "goal_code"
  accepts_nested_attributes_for :goal_entries
end

and for GoalEntry :

class GoalEntry < ActiveRecord::Base
  attr_accessible :code, :goal_code,
  :general_increase_percentage, :general_net_sales,
  belongs_to :goal, :primary_key => "code", :foreign_key => "goal_code"
  validates_presence_of :code
  validates_presence_of :goal_code
  validates_uniqueness_of :code , :scope => :goal_code
  #validates_numericality_of :general_net_sales

The view to create/edit a GoalEntry for the Goal parent starts like this:

<%= form_for([@goal, @goal_entry]) do |f| %>
<% if @goal_entry.errors.any? %>
<div id="error_explanation">
    <h2><%= pluralize(@goal_entry.errors.count, "error") %>
        prohibited this goal_entry from being saved:
    </h2>
    <ul>
        <% @goal_entry.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
        <% end %>
    </ul>
</div>
<% end %>
<div class="field">
    <%= f.hidden_field :goal_code, :required => true%>
</div>
<div class="field">
    <%= f.label :code %>
    <%= f.number_field :code, :required => true %>
</div>
...

The update method in the goal entries controller:

  def update
    @goal_entry = GoalEntry.find(params[:id])

    respond_to do |format|
      if @goal_entry.update_attributes(params[:goal_entry])
        format.html { redirect_to edit_goal_path(@goal_entry.goal), notice: 'Goal entry was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @goal_entry.errors, status: :unprocessable_entity }
      end
    end
  end

Entering valid Goal entries works fine. But if there’s a validation error message I get the following Message:

    **NoMethodError in Goal_entries#update**
ActionView::Template::Error (undefined method `goal_entry_path' for #<#<Class:0x007fce30a0c160>:0x00000004199570>):
    1: <%= form_for([@goal, @goal_entry]) do |f| %>
    2: <% if @goal_entry.errors.any? %>
    3: <div id="error_explanation">
    4:  <h2><%= pluralize(@goal_entry.errors.count, "error") %>
  app/views/goal_entries/_form.html.erb:1:in `_app_views_goal_entries__form_html_erb__827873423371803667_70261777948540'
  app/views/goal_entries/edit.html.erb:3:in `_app_views_goal_entries_edit_html_erb__779650500016633360_70261777920720'
  app/controllers/goal_entries_controller.rb:77:in `block (2 levels) in update'
  app/controllers/goal_entries_controller.rb:72:in `update'
    etc...

Is there something wrong with <% if @goal_entry.errors.any? %>
I’ll appreciate if somebody has a solution for this. 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-06-15T13:29:56+00:00Added an answer on June 15, 2026 at 1:29 pm

    Your form_for is generating its route from [@goal, @goal_entry] but you haven’t defined @goal in your update action.

    Try adding @goal = Goal.find(params[:goal_id]) to your update method.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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

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.