Posted in Multi Model Sign-up Wizard
Related to my previous thread (https://gorails.com/forum/structure-guidance-multi-tenancy-authentication-authorization) I plan to have authorization with Devise and some sort of role based system (perhaps Pundit) tied to a Company model.
When the user signs up they are creating the new Company record and a user / role at the same time. I can see a few issues and I am not sure how to handle them:
1.) Email adress vs username
Some quick Googling indicates that email addresses as username might be a bit more prone to security issues but personally it's nice to use them as it's easy to remember and saves one less field from the scheme. Any thoughts?
2.) Duplicate Companies
With my target market I don't this being a big issue. I am going to require the company name - ABC Widgets Inc. for example. It is possible for two people to sign up "ABC Widgets Inc." and "ABC Widgets" etc. I could do a validation search to look for similar companies but that opens up privacy issues. I was also thinking that I could add a search on existing user email domains too. If [email protected] tries to register "ABC Widgets Inc." and then [email protected] tried to register "ABC Widgets" that would be a chance to stop them and email Sally about Tom's interest.
My first thought is to just leave it along an monitor new signups etc and contact the users when issues arise. I may me making this a bigger issue.
3.) Updating two models at the same time
The user fills out the sign-up form and then my controller chugs away planning to add a Company, User and Role record. I need all three to execute successfully otherwise roll back - can you do that in Rails? The Role is easy - it's a new company and in my system the user could actually already exist.
It took me forever to build but I did it from scratch a few years back on a project that I still have yet to finish. I works slick but I am sure it could be done better than the way I did it. I used the ancestry gem and a few Railscasts episodes to cobble it together.
I forgot we had this thread going? I was using EV's on my server but after the last reboot they got wiped? How do I keep these persistent or do the symlink like you mention above?
Chris - can you elaborate on this or point me to a tutorial on setting this up? I had done this with ENV variables but after my last VPS reboot they all seemed to be lost and I can't recall how I set them before.
Here is a Pro episode suggestion - take this and add nested comments and some AJAX to it :)
Yup - way ahead of you. It was:
# passenger_ruby /home/deploy/.rbenv/shims/ruby; # If you use rbenv
that I forgot to change. Now that I fixed that I am hitting:
Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`
This looks like a Rails 4.1 feature that I had not seen before. I copied and pasted the test key for now and created a dummy index.html file in the public folder and I am up and running finally! Next is to figure out how to set the determine and set key base (and others such as passwords etc.) env variable on the remote server. Thanks for your help.
Thanks Chris - that did the trick. Now I have an entire new issue that is beyond this thread. Passenger won't start:
cannot load such file -- bundler/setup (LoadError) /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code' /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler' /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code' /usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app' /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>' /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>' /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
I turned on the user friendly errors. I will do some Googling but have a suspicion that my ruby versions are different. I have 2.1.3 on my server but the error page shows 1.9.3.
[email protected]:~/oilfieldlocator/releases/20141210203639$ RAILS_ENV=production bundle exec rake db:create PG::InsufficientPrivilege: ERROR: permission denied to create database : CREATE DATABASE "locator_production" ENCODING = 'unicode'
Now I know enough to add create privileges to my user but going forward what would be the 'least privileges' that this user should have from a security standpoint?
[email protected]:~/oilfieldlocator/shared$ RAILS_ENV=production bundle exec rake db:create Could not locate Gemfile
Do I run this from the latest releases directory?
Ok - some headway. I forgot to update the database.yml file on the server and I had some username / password issues. Now I seem to have a chicken and the egg issue. I get the process on the tutorial where after your first deploy you run rake to initialize the database on the server but my deploy seems to be trying to connect before the repository is even uploaded:
INFO[a0fcf2e4] Running ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate on 184.108.40.206 DEBUG[a0fcf2e4] Command: cd /home/deploy/oilfieldlocator/releases/20141210203639 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.3 RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake db:migrate ) DEBUG[a0fcf2e4] rake aborted! DEBUG[a0fcf2e4] ActiveRecord::NoDatabaseError: FATAL: database "locator_production" does not exist DEBUG[a0fcf2e4] Run `$ bin/rake db:create db:migrate` to create your database
I would run rake but nothing has been uploaded to the 'current' directory to run it from.
Changed that to host: 127.0.0.1, ran:
git add. git commit -m "update" git push cap production deploy
I don't think capistrano is getting the most recent git repository because I still get the same errors with the external IP reference:
INFO[b739d356] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on 220.127.116.11 DEBUG[b739d356] Command: cd /home/deploy/oilfieldlocator/releases/20141210201232 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.3 RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile ) DEBUG[b739d356] rake aborted! DEBUG[b739d356] ActiveRecord::AdapterNotSpecified: '18.104.22.168' database is not configured. Available: ["default", "development", "test", "production"]
default: &default adapter: postgresql encoding: unicode # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: 5 development: <<: *default database: locator_development test: <<: *default database: locator_test production: <<: *default url: 22.214.171.124 database: locator_production username: oilfieldlocator #password: <%= ENV['LOCATOR_DATABASE_PASSWORD'] %> password: *************
I have been too lazy to get around to setting the ENV variables
Ok - I think I sort of sorted this out. I had not committed / pushed my site to git.
I did that and now I am having endless issues just trying to get the empty default rails app to deploy.
I can't seem to get the deploy to work at all. Here is where I am stuck:
INFO[9a80e4f2] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on 126.96.36.199 DEBUG[9a80e4f2] Command: cd /home/deploy/oilfieldlocator/releases/20141210083340 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.3 RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile ) DEBUG[9a80e4f2] rake aborted! DEBUG[9a80e4f2] ActiveRecord::AdapterNotSpecified: '188.8.131.52' database is not configured. Available: ["default", "development", "test", "production"]
I am getting ready to give up on this. That IP is the one for my VPS but I changed that to localhost in my database.yml file. Why do I still see it on the deploy errors??
I am literally following the Setup and Deploy tutorials line for line. I have my local dummy rails app up and running and I am trying to run my first deploy to DigitalOcean. Here is the error I am seeing:
DEBUG[700595ea] Could not locate Gemfile cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host 184.108.40.206: bundle exit status: 10 bundle stdout: Nothing written bundle stderr: Nothing written
There is way more dumped out here but this is the line that triggers it. I already stumbled on the requirement to manually upload your database.yaml file so is this the case again here?
Posted in Setup MacOS 10.10 Yosemite Discussion
I missed the Postgres post-install step where you create the database structure etc. once I did that it was all good. To many terminal tabs open and lost track of what I was doing :)
Posted in Setup MacOS 10.10 Yosemite Discussion
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Posted in Styling with Bootstrap Sass Discussion
Hmmm... not sure what I did but must be an issue with TextMate. Opened my Gemfile again and my gem 'bootstrap-sass', '~> 220.127.116.11' declaration was gone - added it back in and it seems to work now.
Posted in Styling with Bootstrap Sass Discussion
Followed the instructions but the gem does not seem to be loading. The bundle command runs but it is not getting installed. I tried a manual install of the gem but all you get when you load a page is a thrown exception:
File to import not found or unreadable: bootstrap
The scss page tries to load bootstrap but the gem isn't loaded.
I am going to guess it's a rails version or dependency issue but not sure where to start.
I think this is basically like I had set it up but I had the Role model to glue the users to the accounts. This is what authorized the users to switch to a given account and what type of user they were.
I need to dig into Devise and CanCanCan more but I am thinking that I should just be able to use Devise as planned and then add a layer of authorization with CanCanCan using the users Role to set the user type (guest, admin etc.)
I while back I was playing around building an app where you had multiple tenants (Company Model) and a single login (User Model). I then created roles (Role Model) to link the users to the tenants. These roles would typically include "guest", "contractor", "admin" etc. I would then use this to authenticate the users access to various resources associated to each tenant. So one user could be a guest for one company and an admin for the next. This way they had a single login etc.
It works pretty good but I was thinking that I should really try to use Devise for the authentication and CanCanCan for the authorization. After some Googling there seems to be a few approaches to this but nothing seems to just out at me as an elegant use of Devise and CanCanCan to accomplish this vs a from scratch solution.
It seems most of the solutions use subdomains which I could use but I would rather not. Devise-basecamper (https://github.com/digitalopera/devise-basecamper) seems like on the right track but its based pin CanCan and looks a bit stale.
Any ideas would be appreciated.