These are just my shorthand notes for how to start a new webpage with rails. Many of the pages I write have very similar features, so I wanted to have the list of commands that I usually use written down somewhere.
Make the new project
$ rails new basic_rails_project $ cd basic_rails_project
Create the databases on both my laptop (also make test) and the server
$ mysql -u user -p mysql> create database db1; mysql> grant all privileges on db1.* to [email protected] identified by 'password'; mysql> create database db1_test; mysql> grant all privileges on db1_test.* to [email protected] identified by 'password'; mysql > quit; development: adapter: mysql2 encoding: utf8 database: db1 username: user password: password test: adapter: mysql2 encoding: utf8 database: db1_test username: user password: password production: adapter: mysql2 reconnect: true encoding: utf8 database: db1 username: user password: password
I usually add the following gems to my Gemfile. Also make sure to uncomment therubyracer gem.
gem 'capistrano', '2.15.4' # I prefer version 2 which is simpler than version 3 gem 'authlogic' gem 'declarative_authorization' gem 'paperclip' gem 'mysql2', '0.3.20' gem 'kaminari' gem 'ransack' gem 'net-ldap' gem 'prawn' gem 'twitter-bootstrap-rails' gem 'less-rails' $ bundle
Make a Homepage
Don’t need a model for homes as it’s usually just a landing page. So create views/show.html.erb.
Add to routes.rb, resources :homes, only: show
Users table and logins
Scaffolding here works great. All I usually do it delete the extra json stuff in the controller.
Make a settings table
This table will only have one entry. It holds items about the state of the app. For example, there will be a checkbox accepting, telling us whether or not we’re accepting more registrations. This is basically my admin table. It will be created with a seed file and then just edited as necessary.
Set up bootstrap
$ rails g bootstrap:install
Set up git
Login to github and create a new repo named basic_rails_project.
$ git init $ git remote add origin https://github.com/maryheintz/basic_rails_project.git
Normally I’d edit .gitignore and not include files with sensitive information in the repo. Things like database.yml, secrets.yml, environment files that might have email info, etc. For this example, I’m including everything, since this app is never going to run on a real server.
$ git add . $ git commit -a $ git push -u origin master Username for 'https://github.com': maryheintz Password for 'https://[email protected]':
And for those of you interested, you can find my rails app with all the files that I edited on Github.