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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:04+00:00 2026-05-25T21:37:04+00:00

I am using Ruby 1.8.7 and Rails 2.3.5 So I am trying to figure

  • 0

I am using Ruby 1.8.7 and Rails 2.3.5

So I am trying to figure out why my has_many association doesn’t work properly. I have 2 tables in the database, Videos and Comments. Inside the Comments table I have a foreign key of video_id column and when posting a comment nothing shows up on my video’s page because the video_id column is NULL so nothing got posted.. If I add the id of the video in the video_id column, you can view the comment. Am I missing something?

Video.rb

class Video < ActiveRecord::Base
 has_many :comments
end

Comment.rb

class Comment < ActiveRecord::Base  
 belongs_to :video
end

comments_controller.rb

  def create
    @comment = Comment.new(params[:comment])
    @comment.video_id = params[:video_id]    

    if @comment.save
      flash[:notice] = 'Your comment was saved!'
    else
      flash[:notice] = 'Sorry, there was a problem.'
    end

    redirect_to videos_path
  end

_form.html.erb

    <% form_for :comment, :url => comments_path(@video) do |f| %>

    <p>
      <%= f.label :name, "Your Name" %>
      <%= f.text_field :name %>  
    </p>
    <p>
      <%= f.label :body, "Your Comment" %>
      <%= f.text_field :body %>
    </p>
    <p>
      <%= f.submit "Submit", :disable_with => 'Submiting...' %>
    </p>


    <% end -%>

Routes.rb

    ActionController::Routing::Routes.draw do |map|

      map.index     '/',                          :controller => 'homepage', :action => 'index'
      map.logout    '/logout',                    :controller => 'sessions', :action => 'destroy'
      map.signout   '/signout',                   :controller => 'sessions', :action => 'destroy'
      map.login     '/login',                     :controller => 'sessions', :action => 'new'
      map.signin    '/signin',                    :controller => 'sessions', :action => 'new'
      map.register  '/register',                  :controller => 'users',    :action => 'create'
      map.signup    '/signup',                    :controller => 'users',    :action => 'new'
      map.activate  '/activate/:activation_code', :controller => 'users',    :action => 'activate', :activation_code => nil
      map.resources :users 
      map.resource  :session
      map.resources :comments
      map.resources :videos

      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'

    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-25T21:37:04+00:00Added an answer on May 25, 2026 at 9:37 pm

    You’re not specifying params[:video_id] correctly.

    From what I can tell you want to allow users to comment on videos?

    If so, I believe the real routing structure you want is:

    resources :videos do
      resources :comments
    end
    

    This will make a path like video_comments_path(@video) which you can POST to and in the create action do something like:

      @video = Video.find(params[:video_id])
      @comment = @video.comments.create(params[:comment])
    

    Thats basically it

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

Sidebar

Related Questions

Using ruby (not rails), I'm trying to figure out how to replace (not append)
I'm trying to write an app using Ruby on Rails and I'm trying to
I'm trying to build a web service using Ruby on Rails. Users authenticate themselves
I am using ruby on rails with a MySQL backend. I have a table
I have built a blog application using Ruby on Rails. In the application I
I'm using Ruby on Rails with jQuery and trying to do the following: <%=
I am trying to build a free web application using ruby/rails It should be
I was trying to switch the layout using Ruby on Rails but I am
I am trying to set up Ruby on Rails on windows. I am using
I am trying to make a auto complete box using ruby on rails, jquery

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.