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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:56:58+00:00 2026-05-24T02:56:58+00:00

Trying to divide and conquer these problems ( 1 , 2 ) I am

  • 0

Trying to divide and conquer these problems (1, 2) I am still having. I would like to write the first step of a BLT recipe in my nested, many-to-many model from the virtual attribute. Later on I would like to have a more complex form, thus I am doing this in the model.

I have hard-coded everything in the model except for name of the recipe. Here is the Recipe model:

    class Recipe < ActiveRecord::Base
      has_many :steps, :class_name => 'Step'
      has_many :stepingreds, :through => :steps
      has_many :ingredients, :through => :stepingreds
      accepts_nested_attributes_for :steps, :stepingreds, :ingredients
      attr_writer :name_string
      after_save :assign_name

      def name_string
        self[:name]
      end

      def assign_name
        if @name_string
        self[:name] = @name_string
        self[:description] = "Addictive sandwich"
        self.steps = Step.create({
           :number => 1,
           :instructions => 'Cook bacon',
           :stepingreds => [{ :ingredient => { :name => 'Bacon' }, :amount => 4 } ]
          })
       end
    end

And here is the form

    <%= form_for @recipe do |f| %>
        <%= f.error_messages %>
        <p>
          <%= f.label :name_string, "Name" %><br/>
          <%= f.text_field :name_string %>
        </p>
        <p><%= f.submit %></p>
    <% end %>

I get a “NameError in RecipesController#create, undefined local variable or method `attribute’ for #”. I think I have more than one error but this seems like it should work to me. What am I doing wrong?

Thanks!

Edit – Here is the RecipeController create action

   def create
       @recipe = Recipe.new(params[:recipe])
       if @recipe.save
         redirect_to @recipe, :notice => "Delicious BLT created!"
       else
         render :action => 'new'
       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-05-24T02:56:59+00:00Added an answer on May 24, 2026 at 2:56 am

    Here’s a simple Rails application that does what you need:

    https://github.com/pixeltrix/cookbook

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

Sidebar

Related Questions

I am trying to write a divide & conquer algorithm for trees. For the
I'm having an issue trying to divide two decimals and then display the result.
I am trying to divide arrays recursively... I think that is what this would
This is the question I'm trying to solve: The following divide-and-conquer algorithm is proposed
Trying to write such function. It must divide text into multiple columns and the
I'm trying to divide a page in three parts. I'd like to do it
Trying to get my css / C# functions to look like this: body {
I am implementing a divide and conquer polynomial algorithm so I can benchmark it
I'm trying to divide long text in small parts, so that every part is
I'm trying to divide a string into parts for reading Roman numerals. For example

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.