I am using Rails 4 and Devise 3 and Postgresql for my database. How can I enter a user through the terminal into my user table?
rails db
is how I enter into the database.
$ rails console
rails > User.create email: 'john#example.com', password: 'password', password_confirmation: 'password'
Related
I use active_admin in local environment and it works fine.
I can login as adminuser after executing "rake db:seed".
(here is my seed.rb file)
AdminUser.create!(email: '1#1', password: '123456', password_confirmation: '123456') if Rails.env.development?
However in production environment, I can't access to active_admin page as admin_user.
I already tried "rake db:seed RAILS_ENV=production" but it's not working.
(here is my seed.rb file in production mode)
AdminUser.create!(email: '1#1', password: '123456', password_confirmation: '123456') if Rails.env.production?
(here is my logs)
Anyone plz help thanks!
I am running through Hartl's Rails tutorial, but when I try to seed Microposts I am getting the error: "ActiveRecord::RecordInvalid: Validation failed: Email has already been taken"
I did db:migrate:reset followed by db:seed which throws up the error. Is there something wrong with what I am trying to seed?
User.create!(name: "Example User",
email: "example#railstutorial.org",
password: "foobar",
password_confirmation: "foobar",
admin: true,
activated: true,
activated_at: Time.zone.now)
99.times do |n|
name= Faker::Name.name
email = "example-#{n+1}#railstutorial.org"
password = "password"
User.create!(name: name,
email: email,
password: password,
password_confirmation: password,
activated: true,
activated_at: Time.zone.now)
end
users = User.order(:created_at).take(6)
50.times do
content = Faker::Lorem.sentence(word_count: 5)
users.each { |user| user.microposts.create!(content: content) }
end
You have probably already created some records in the database, which invokes validation. To check this, run the console rails c and then type User.first.
If you have some records run rake db:reset to reset database.
If you want to be able to run the seed multiple times, write
User.find_or_create_by(email: email) do |u|
u.name: name,
u.password: password,
u.password_confirmation: password,
u.activated: true,
u.activated_at: Time.zone.now
end
instead your code.
Instead of create! user create so if the email address is already taken, the record would not be created and the script gracefully continues, and you won't get an exception.
I'm not sure what exactly happened but I went ahead and reset my migrations once more and when I reseeded it worked. So if anyone else has this problem in the future, just clear the database again and try again.
In my case I had a syntax error when calling Rake :: .....
It worked for me to update the gem with gem 'faker', '~> 2.15', '> = 2.15.1'
Then rails db: migrate: reset and rails db: seed.
I am trying to seed my database, but I am running into this error where its telling me with_deleted is an undefined method in my seeds.rb:
User.with_deleted.each(&:really_destroy!)
User.create(
email: 'admin#example.com',
roles: [:admin],
password: 'abc123',
password_confirmation: 'abc123',
)
I believe it should have been defined from the paranoia gem. Can anyone suggest a workaround? I am working in Rails 5.1.
I tried both of these:
#user = User.create(
email: 'admin#example.com',
roles: [:admin],
password: 'abc123',
password_confirmation: 'abc123',
)
and
User.create(
email: 'admin#example.com',
roles: [:admin],
password: 'abc123',
password_confirmation: 'abc123',
)
and it looked like it worked but when I did a User.last in rails c I still got nil
As far as including act_as_paranoid in my User.rb file, this is what I have:
# acts_as_paranoid
include AddressFields
include MeAssessmentScoring
Is this not enough? But ultimately, can I just get this working without having to involve the paranoia gem? So far, what I have tried above has not worked and when I try to create a user within rails c, I get:
ActiveRecord::RecordInvalid: Validation failed: First name can't be
blank, Last name can't be blank
when I ran this: user = User.create!(email:'admin1#example.com', roles:'admin',password:'abc123', password_confirmation:'abc123')
I was able to get up and running by executing the following:
heroku pg:backups:capture
heroku pg:backups:download
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d thirdelementweb_development latest.dump
I have a rails 5 app running the latest devise and I'd like to create valid users for testing with the fixtures, but I can't update the password as the way devise has users set up there is no passwords column in the users table.
Is there a way to set the fixture up to work around this and have a working user?
text/fixtures/users.yml:
jeremy:
email: jeremy#someemail.com
provider: facebook
username: Jeremy
password: password
any test using that user returns:
ActiveRecord::Fixture::FixtureError: ActiveRecord::Fixture::FixtureError: table "users" has no column named "password".
Prepare your test database.
rake db:migrate
rake db:test:prepare
I'm trying to use Cucumber in a Rails 4. I've added the Cucumber-Rails gem, followed the steps in the instructions but when I wrote step definitions like so:
When(/^I submit a sign up with the following:$/) do |table|
user = User.create({
first_name: 'Name',
last_name: 'Last',
email: 'email#example.com',
domain: 'example.com',
password: 'foobar',
password_confirmation: 'foobar'
})
end
I get the following error: uninitialized constant User (NameError)
./features/step_definitions/users/sign_up_steps.rb:2:in/^I submit a sign up with the following:$/'
features/users/sign_up.feature:4:in When I submit a sign up with the following:'
What am I missing?
Please check , it's looking like you have missed the User model
User model is missing for which you are running tests.