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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:47:39+00:00 2026-06-03T18:47:39+00:00

I’ve a couple of model I’ve made using the scaffold generator. There are: rails

  • 0

I’ve a couple of model I’ve made using the scaffold generator.

There are:

rails g scaffold event title:string content:text
rails g scaffold link title:string

I would like that each event has many links, and link belongs to events.

So in the event models I’ve coded:

has_many :links

And inside the link model:

belongs_to :event

Moving on I’ve run:

rake db:migrate

In order build the database. And I’ve made a couple of events using scaffold feature.

Now I’d like to add links directly inside the event’s show>views.

Inside the show.html.erb (inside the view>events dir) I’ve written:

<%= form_for([@event, @event.links.build]) do |f| %>

<p><%= f.text_field %></p>
<p><%= f.submit "Add the link" %></p>
<% end %>

But when I try to visit the show page the browser says:

unknown attribute: event_id 

And it says the error is on this line:

<%= form_for([@event, @event.links.build]) do |f| %>

What I did wrong?

Thanks in advance

  • 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-03T18:47:41+00:00Added an answer on June 3, 2026 at 6:47 pm

    You must create the foreign key in your migrations, the event_id, by changing the existing ones or creating a new one.

    Since you have already migrate them it’s recommended you create a new one, so it should be something like this

    class AddEventForeignKeyToLinks < ActiveRecord::Migration
      def up
        change_table :links do |t|
          t.references :event
        end
      end
    
      def down
        remove_column :links, :event_id
      end
    end
    

    Edit: Don’t forget that to create the migration file you should use the command

    rails generate migration AddEventForeignKeyToLinks
    

    Or any other name then AddEventForeignKeyToLinks


    routes

    resources :events do 
      resources :links 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I am reading a book about Javascript and jQuery and using one of the

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.