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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:47+00:00 2026-06-09T12:33:47+00:00

Rails newbie working on associating tasks with lists and running into trouble when I

  • 0

Rails newbie working on associating tasks with lists and running into trouble when I try and interact with forms after I start the rails server.

Here’s the error I’m getting. Any ideas?

Thanks!

NoMethodError in TasksController#create

undefined method `find_or_create_by_name' for #<Class:0x00000102a8bad0>
Rails.root: /Users/user/rails_projects/todolist

Application Trace | Framework Trace | Full Trace
app/models/task.rb:15:in `list_name='
app/controllers/tasks_controller.rb:43:in `new'
app/controllers/tasks_controller.rb:43:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"B7g7u+v5USPRhefdFPt84xGkKjB1nVwy62IJj6SHJpc=",
 "task"=>{"description"=>"Milk",
 "list_name"=>"Shopping"},
 "commit"=>"Create Task"}

ListsController:

class ListsController < ApplicationController

      # GET /lists
      # GET /lists.json
      def index
      @lists = List.all

      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @lists }
      end
    end

    # GET /lists/1
    # GET /lists/1.json
    def show
      @list = List.find(params[:id])

      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @list }
      end
    end

    # GET /lists/new
    # GET /lists/new.json
    def new
      @list = List.new

      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @list }
      end
    end

    # GET /lists/1/edit
    def edit
      @list = List.find(params[:id])
    end

    # POST /lists
    # POST /lists.json
    def create
      @list = List.new(params[:list])

      respond_to do |format|
        if @list.save
          format.html { redirect_to @list, notice: 'List was successfully created.' }
          format.json { render json: @list, status: :created, location: @list }
        else
          format.html { render action: "new" }
          format.json { render json: @list.errors, status: :unprocessable_entity }
        end
      end
    end

    # PUT /lists/1
    # PUT /lists/1.json
    def update
      @list = List.find(params[:id])

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

    # DELETE /lists/1
    # DELETE /lists/1.json
    def destroy
      @list = List.find(params[:id])
      @list.destroy

      respond_to do |format|
        format.html { redirect_to lists_url }
        format.json { head :no_content }
      end
    end
  end

TasksController:

class TasksController < ApplicationController

      # GET /tasks
      # GET /tasks.json
      def index
      @tasks = Task.all

      respond_to do |format|
       format.html # index.html.erb
       format.json { render json: @tasks }
    end
  end

  # GET /tasks/1
  # GET /tasks/1.json
  def show
    @task = Task.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @task }
    end
  end

  # GET /tasks/new
  # GET /tasks/new.json
  def new
    @task = Task.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @task }
    end
  end

  # GET /tasks/1/edit
  def edit
    @task = Task.find(params[:id])
  end


  # POST /tasks
  # POST /tasks.json
  def create
    @task = Task.new(params[:task])

    respond_to do |format|
      if @task.save
        format.html { redirect_to @task, notice: 'Task was successfully created.' }
        format.json { render json: @task, status: :created, location: @task }
      else
        format.html { render action: "new" }
        format.json { render json: @task.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /tasks/1
  # PUT /tasks/1.json
  def update
    @task = Task.find(params[:id])

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

  # DELETE /tasks/1
  # DELETE /tasks/1.json
  def destroy
    @task = Task.find(params[:id])
    @task.destroy

    respond_to do |format|
      format.html { redirect_to tasks_url }
      format.json { head :no_content }
    end
  end
end

Task model:

class Task < ActiveRecord::Base

    attr_accessible :description, :list_name

    belongs_to :list, :foreign_key => "list_id" 

   def name
      @list = List.find(params[:id])
    end

    def list_name
      list.name if self.list 
    end

    def list_name=(str)
      self.list = List.find_or_create_by_name(str) 
    end

  end

List model:

class List < ActiveRecord::Base

    attr_accessible :title
    has_many :tasks 

    def name
      @list = List.find(params[:id])
    end

  end

Partial for Tasks:

    <%= form_for(@task) do |f| %>
    <% if @task.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@task.errors.count, "error") %> prohibited this task from being        saved:</h2>

      <ul>
      <% @task.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :description %><br />
    <%= f.text_area :description %>
  </div>
  <div class="field">
    <%= f.label :list_name %><br />
    <%= f.text_field :list_name %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Partial for Lists:

   <%= form_for(@list) do |f| %>
    <% if @list.errors.any? %>
      <div id="error_explanation">
        <h2><%= pluralize(@list.errors.count, "error") %> prohibited this list from being saved:</h2>

        <ul>
        <% @list.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
        </ul>
      </div>
    <% end %>

    <div class="field">
      <%= f.label :title %><br />
      <%= f.text_field :title %>
    </div>
    <div class="actions">
      <%= f.submit %>
    </div>
  <% 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-09T12:33:48+00:00Added an answer on June 9, 2026 at 12:33 pm

    Rails’ dynamic finders (find_by_... and find_or_create_by_...) are generated using the attributes of a model. You were using find_or_create_by_name when name wasn’t an attribute on the List model.

    Changing that to find_or_create_by_title(...) fixes the problem.

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

Sidebar

Related Questions

Rails newbie here, trying to get a new controller working. When I try to
As a Rails newbie, I am running into an issue in which I can
So, I'm admittedly a Rails newbie, and I'm running into what must be a
I'm a newbie working through Michael Hartl's Tuby on Rails Tutorial and I have
I am a newbie in Rails and am working on a page that enables
I am a newbie to Ruby on Rails . I have started working on
I am Rails newbie and having some trouble passing parameters to form. I have
I am a ruby and rails newbie. And I am working on a rails
I am a complete newbie in working with a Ruby on Rails (RoR) application.
I'm a jquery/rails newbie and I'm having trouble using .sortable(). I have expandable rows

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.