am new to rails & this is my first app .. I used devise & CanCan for authentication & authorization & there was a predefined set of roles for every user that I can assign it to ... Working perfectly on my local machine .. once deployed to Heroku & migrated the database everything seemed in place but when I tried to assign a role to a user there was none .
Any idea what's wrong?
I also wanted to disable the sign-up & only allow admins to create users
Thanks in advance
EDIT:
After too much searching I found out that the missing part is the Role table from the rolify gem, for some reason it refuses to migrate on the PostgreSQL/Heroku.
& the issue is raised in this link, still didn't find a solution that worked for me
https://github.com/EppO/rolify/issues/76
You might need to run all the migrations on Heroku. Do this: heroku run rake db:migrate and try again.
Related
I've been assigned to work on a legacy Rails app, and nobody has a development environment working. I've gotten everything up and running, but I can't create a new user on my development environment because the facebook api doesn't like the api call originating from an IP that isn't the production server, and the mailer for the non facebook signup times out for the same reason. I've narrowed it down to a couple options:
Figure out a way to get the facebook api to accept the request from my development box
Fix the mailer or wrap it in a conditional so that email confirmation is not required in the development environment
Manually add a user to the database
Which option is best, and how would I go about doing it? I'm relatively new to rails and backend programming. Options one and two seem like potential security risks, but I have no idea how to go about doing option 3. I tried adding User.create([{email: '(redacted)'}, {password: '(redacted)'}]) to the seeds.rb file and running db:seed with no luck.
Suggestions?
Your easiest option is definitely simply to create the new user manually. Instead of launching your rails server ($ rails s), launch your rails console ($ rails c). From this command line (which is identical to the debugger, if you've ever used that before), you may create a user and save it. You will still be subject to the validations in the User model, but something along the lines of the following should work:
new_user = User.new( email: 'myemail#example.com', name: 'Joe Smith' )
new_user.save
As long as you match the validations of the model, and connect to the appropriate database, this is a very simple approach. To connect to the right database, either update config/database.yml so that your development environment is the one you want to hit, or run specifically in the correct environment (if it's production, as you implied, simply run $ rails c RAILS_ENV=production instead of the aforementioned$ rails c).
I'm getting a database error in production. But in development no error.
ActiveModel::MissingAttributeError (can't write unknown attribute `invited_by_id`):
invited_by_id is a column added by the Devise Invitable gem to my User table. I encountered this error after pushing my Devise Invitable implementation to production for the first time and then attempting to invite a new user.
I have confirmed that invited_by_id IS present in both my development and production tables. I have checked this multiple times via Rails console for each environment. I have also done rake db:migrate twice for good measure (in production) with the first time adding the Devise Invitable columns and the second time, of course, having no new migrations to run since the columns were already added. There are also numerous other columns added by Devise Invitable to the same User table that were successfully migrated and are not creating errors. I have successfully edited one as well. (Google Searches, Devise Invitable Github issues, and a thorough review of my development and production environment fields have yielded nothing but encouragement to check that the column is present -- which it is.)
Is there something to be aware of with Devise Invitable, User tables, or with development versus production databases for a situation like this? For some additional context, I am using Devise Invitable 1.5.5, Rails 4.2.4, and my production database is on Heroku.
Thank you!
ActiveModel::MissingAttributeError (can't write unknown attribute `invited_by_id`)
Looking at this error message, you are missing invited_by_id column in your production database. Make sure you run your migrations on production environment and try again. That should fix your problem.
Here is the same issue reported on the gem's github page.
You can also try restarting your heroku app which seems to fix this type of issues many times :)
Wondering if anyone tried this before, I'm trying to migrate devise users from one project(postgres) to another(mongoid).
I've created a script with takes users from sql table and create mongo inserts out of it, all was running fine, but for some reason devise on new project not able to auth migrated users.
encrytpted_password field looks ok.
Can someone please advise if I've missed something?
So I've set up a new authentication process within my website using rails (rails version '4.2.0', sqlite3 database manager, ruby 2.1.1p76) on OSX Mavericks (yes, I still haven't updated yet!). The website as yet is still only local as I'm learning rails.
I have modified the user authentication to utilise a cookies remember me function, but old users can not login, i.e. error Couldn't find User (ActiveRecord::RecordNotFound in WelcomeController#homepage)
Newly created users can.
I was just wondering what the terminal command is to somehow to delete all records of users from the database, so that all new users need to sign up to obtain the remember me functionality...? I can't seem to find the exact answer and I don't want to start messing too much with the database.
Start a rails console by typing
rails c
in the terminal, in your rails application folder (not the app subfolder).
type
User.destroy_all
I added some columns to a table using rails and rake, but they do not show up in rails admin. What might be a reason for this? I am successfully registering new objects using them...
Turns out I just needed to restart the rails server.