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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:42:01+00:00 2026-05-27T10:42:01+00:00

I am having a text file that contains users name.I want to extract users

  • 0

I am having a text file that contains users name.I want to extract users name from the text file and insert it into the table via db migrations.Here the extraction part works fine.There are no errors displayed with rake db:migrate.
But the data is not seen in the database.

class AddUsers< ActiveRecord::Migration
   def self.up
     i=0
     File.open("users").each do |line|
     if i>=4 && line=~/^(\s)+[a-z]+/
         word=line.split("|")
         word[0]=word[0].strip
         email=word[0]+"\@sandvine.com"
         puts "word=#{word[0]},email=#{email}"
         User.create :name =>#{word[0]}, :email => #{email}
         puts "created"
     end
     i=i+1
   end
end

 u=User.create(:name => "ramyameena", :email  => "ramyameena@sandvine.com",:password=>"sandvine",:roles=>{:id=>2,:name=>"Tester"})
=> #<**User id: nil**, name: "ramyameena", created_at: nil, updated_at: nil, email: "ramyameena@sandvine.com", encrypted_password: "$2a$10$qIfRLKZlxviag9E0Gzvp8e3VKkOCaXraP7PnJC6vGMN....", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil>

irb(main):012:0> u.errors.inspect
=> "#<OrderedHash **{:roles=>[\"can't be blank\"]**}>"

My users model:

class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :name, :presence => true, :uniqueness => true
validates :roles, :presence => true
has_many :user_role_assignments
has_many :roles, :through => :user_role_assignments
has_many :tester_release_assignments
has_many :releases, :through => :tester_release_assignments
has_many :releases
has_many :ic_runs
accepts_nested_attributes_for :user_role_assignments
attr_accessible :email, :name, :password, :password_confirmation, :role_ids

thanks,
Ramya.

  • 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-27T10:42:02+00:00Added an answer on May 27, 2026 at 10:42 am

    The #{...} syntax is used to interpolate ruby in a string. You’re using it correctly here:

    puts "word=#{word[0]},email=#{email}"
    

    but then incorrectly here:

    User.create :name =>#{word[0]}, :email => #{email}
    

    Here the # is actually commenting out the rest of the line (as you can even tell by the syntax highlighting here). It’s curious that you don’t get any syntax errors when running this code, but at best the result is undefined. What you want is this:

    User.create(:name => word[0], :email => email)
    

    as @dexter alread noted.

    BTW, this is one reason to use braces even if you don’t have to, because this:

    User.create(:name =>#{word[0]}, :email => #{email})
    

    would definitely throw a syntax error since the closing brace is commented out.

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

Sidebar

Related Questions

I have a File having text and few numbers.I just want to extract numbers
I'm having a problem where instead of reading a text file from the location
How to convert the text file through vb6 code. Having filename like clock.fin, time.mis,
How to copy the text file through vb6 code. Having Source filename like clock.fin,
I am sending mails (in asp.net ,c#), having a template in text file (.txt)
I am having utf-8 encoded file containing arabic text and I have to search
I am having problems getting text within a table to appear centered in IE.
I have xml file that contains the URLs for geocoding requests to Google. I
I have a file log that I would like to parse and am having
I'm having this problem with validating a document that contains some basic PHP variables.

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.