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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:00:43+00:00 2026-05-21T04:00:43+00:00

I am new to Ruby and Rails so sorry if this looks too noob.

  • 0

I am new to Ruby and Rails so sorry if this looks too noob.
I have created a resource called stream and another resource called tasks and have mapped them properly using has_many and belong_to. Everything works until I decided to add a “Quick Task Add form” on my Stream.show view:

Here is the view code for the form:

<%= form_for(@task) do |f| %>
    <%= render 'shared/error_messages', :object => f.object %>
  <div class="field">
    <%= f.text_field :title %>  <%= f.submit "Add Task" %>
<%= hidden_field_tag(:stream_id, @stream.id) %>
  </div>
<% end %>

Here is my Stream.show action:

def show
  @stream = Stream.find(params[:id])
  @user = User.find(@stream.user_id)
  @tasks = @stream.tasks.paginate(:page => params[:page])
  @title = @stream.title
  @task = Task.new
end 

And here is my task controller:

class TasksController < ApplicationController

  def create
    @stream  = Stream.find(params[:stream_id])
    @stream.tasks.create!({:title => params[:task][:title], :user_id => 1, :owner => 1})

    if @stream.save
      flash[:success] = "Task created succesfully!"
    else
      flash[:error] = "Error creating task"
    end

    redirect_to @stream
  end
end

Looks pretty basic to me. The problem is when it executes tasks.create, I get the following error message: “Validation failed: User can’t be blank, Owner can’t be blank”

What am I doing wrong?

edit: adding model code from comment

class Stream < ActiveRecord::Base 
  attr_accessible :title 
  belongs_to :user 
  has_many :tasks, :dependent => :destroy 
  validates :title, :presence=> true, :length => { :maximum =>50 } 
  validates :user_id, :presence => true 
end 

class Task < ActiveRecord::Base 
  attr_accessible :title 
  belongs_to :stream 
  validates :title, :presence=> true, :length => { :maximum =>70 } 
  validates :user_id, :presence => true 
  validates :owner, :presence => true 
  validates :stream_id, :presence => true 
  default_scope :order => "updated_at" 
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-21T04:00:43+00:00Added an answer on May 21, 2026 at 4:00 am

    You should set your user_id and owner fro STREAM object

    class TasksController < ApplicationController
    
      def create
        @stream  = Stream.find(params[:stream_id])
        @stream.tasks.create!({:title => params[:task][:title], :user_id => 1, :owner => 1})
        @stream.user_id = 1
        @stream.owner = 1
        if @stream.save
          flash[:success] = "Task created succesfully!"
        else
          flash[:error] = "Error creating task"
        end
    
        redirect_to @stream
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new with ruby and rails and have been struggling with this issue for
I am new to Ruby and Rails so bear with me please. I have
I am a new Ruby on Rails user and had a question. I have
I'm new to Ruby on rails and am a bit confused. I have an
I am new to rails so sorry if this is easy. I am wondering
I am new to ruby on rails. I have passed parameters ISDCode,AreaCode and Telephone
I am new to Ruby on Rails and have been helped immensely by Michael
I created a new Ruby on Rails 3.0.1 project, and then globally updated gems
I created a new Ruby on Rails 3.0.1 project, and then globally updated gems
I am looking for NEW Ruby on Rails resource websites (Screencasts, Tutorials, etc) some

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.