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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:59:00+00:00 2026-06-11T03:59:00+00:00

In my ROR project, I came across an issue. Previous developer of the project

  • 0

In my ROR project, I came across an issue. Previous developer of the project has save an array of data into a single column for a particular field. But now I have to get those data and save it to another separate table with the current table id. Following is my code for get the details from the db:

@ar = AResponse.select("id, selected_barriers");
    @ar.each do |p|
      p.selected_barriers.each do |barrier|

      end
    end

What I wanted is I have to save the p.id and barrier to a new table and I have to do it in a migration file. So when the migration runs, it will get all the existing details from AResponse and save it to the new one. Can I do it only with migration file? If so how can I do it?

This is my full code

I tried but its not working: Following is my code

class AnalysisBarriers < ActiveRecord::Migration
  def self.up

  end

  def change
    create_table :analysis_barriers do |t|
      t.integer :analysis_response_id, :null => false
      t.string :barrier
    end
    @analysis_response = AnalysisResponse.select("id, selected_barriers");
    @analysis_response.each do |p|
      p.selected_barriers.each do |barrier|
        AnalysisBarriers.create(:analysis_response_id => p.id, :barrier => barrier)
      end
    end
  end
  def self.down
    drop_table :analysis_barriers
  end
end

Thanks

  • 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-11T03:59:02+00:00Added an answer on June 11, 2026 at 3:59 am

    Yes you can do data changes after migrations. Whatever data changes you want to do, you can do in change function or up function. Take the following example

    class Event < ActiveRecord::Migration
      def change
        create_table events do |t|
          t.datetime :starts_at
          t.datetime :ends_at
          t.timestamps
        end
        Event.create(:starts_at => Time.now, :ends_at => Time.now+1)
      end
    end
    

    Above statement will add data to your table just after its creation.

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

Sidebar

Related Questions

I'm new to RoR and started making a project recently. The project has public/stylesheets
I have a RoR project on my Windows 7 PC. I want to create
I'm using static URLs in my RoR project. There is really no controller or
After installing RBEnv and rebuilding my ROR project, I now seem to have added
I currently have the following models/toy.rb file in my RoR project: class ToysPurchased include
are there different sensitivities/settings to whitespace in ruby? i have a RoR project, where
I'm looking for some guidance for a personal project of mine in RoR. I
I've a problem with a slow post request in a RoR app. the project
i'm not a full RoR developer (php developer mostly), i've only don't small projects/tutorials,
We are a GIS RoR-based software company which works with spatial data. At 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.