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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:10:00+00:00 2026-06-15T06:10:00+00:00

When I go to new_heuristic_variant_cycle_path , my app displays the new view for cycle,

  • 0

When I go to new_heuristic_variant_cycle_path, my app displays the new view for cycle, but the submit button on the form says “Update Cycle” not “Create Cycle”, and when you click the submit button the controller goes looking for an update action. Why?

I have…

/config/routes.rb:

Testivate::Application.routes.draw do
  resources :heuristics do
    resources :variants do
      resources :cycles
    end
  end
end

/app/models/heuristics.rb:

class Heuristic < ActiveRecord::Base
  has_many :variants
  has_many :cycles, :through => :variants
end

/app/models/variants.rb:

class Variant < ActiveRecord::Base
  belongs_to :heuristic
  has_many :cycles
end

/app/models/cycles.rb:

class Cycle < ActiveRecord::Base
  belongs_to :variant
end

/app/views/cycles/new.html.haml:

%h1 New Cycle
= render 'form'

/app/views/cycles/_form.html.haml:

= simple_form_for [@heuristic, @variant, @cycle] do |f|
  = f.button :submit

/app/controllers/cycles_controller.rb:

class CyclesController < ApplicationController
  def new
    @heuristic = Heuristic.find(params[:heuristic_id])
    @variant = @heuristic.variants.find(params[:variant_id])
    @cycle = @variant.cycles.create
    respond_to do |format|
      format.html # new.html.erb
    end
  end
  def create
    @heuristic = Heuristic.find(params[:heuristic_id])
    @variant = @heuristic.variants.find(params[:variant_id])
    @cycle = @variant.cycles.create(params[:cycle])
    respond_to do |format|
      if @cycle.save
        format.html { redirect_to heuristic_variant_cycles_path(@heuristic, @variant, @cycle), notice: 'Cycle was successfully created.' }
      else
        format.html { render action: "new" }
      end
    end
  end
end
  • 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-15T06:10:00+00:00Added an answer on June 15, 2026 at 6:10 am

    In your controller, this line of code is wrong:

    @cycle = @variant.cycles.create
    

    It should be this:

    @cycle = @variant.cycles.build
    

    When you call create, the record is saved. In the doc:

    collection.build(attributes = {}, …)

    Returns one or more new objects of the collection type that have been instantiated with attributes and linked to this object through a foreign key, but have not yet been saved.

    collection.create(attributes = {})

    Returns a new object of the collection type that has been instantiated with attributes, linked to this object through a foreign key, and that has already been saved (if it passed the validation). Note: This only works if the base model already exists in the DB, not if it is a new (unsaved) record!

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

Sidebar

Related Questions

New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
New to WCF, but familiar with COM+ - can I wrap a WCF service
NEW EDIT: I have narrowed my problem to this - i have a view
New question, but really close to need to refresh page in jquery mobile .
new to JavaScript seeking some help. I have a form with a select drop
New to matlab and I need some help. I need to create a .mat
New to Rails... here goes: If I want my 'create' method to respond differently
New to linux and c++. I wante to create an application that only needs
I've been trying to understand the stochastic hill climber for a while, but not
My question is rooted in T-SQL, SQL Server environment, but its scope is not

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.