Installing Ruby on Rails on OS X.
brew install mysql
brew install mysql@56
bundle install
Create new rails
app with mysql
as the default.
rails new <my_rails_app> --database=mysql
Default rails comes with Webrick but I dislike having to stop and restart my web server regularly. Instead, I use rerun
to monitor my file edits and restart the server every time I make a change. livereload
is also very popular.
rerun --dir config rails s
If you leave all the settings on default, you should be able to access your new website on:
http://localhost:3000
I generally recommend that new rails developers get into the habit of manually creating their own controllers, routes, view templates and partials but scaffolding can come in handy too.
Models are the classes that you use to populate and retrieve data from a database. They're exceptionally useful for validating data before you write anything to a database so treat them with kindness and respect.
rails g model mymodel title:string description:text file_url:string
Controllers are the methods you use to access data, manipulate it, and publish it to view templates. These methods are oftentimes accessed by admin/routes
which are triggered by REST requests.
[Scaffolding a Controller]((http://stackoverflow.com/questions/2504123/generate-a-controller-with-all-the-restful-functions)
rails g scaffold_controller ClassName
is the shorthand way of writing this:
rails g controller mycontroller new create update edit destroy index show
If you mess up your command and you need to re-build your controller, I suggest trying this. It will re-create (and forcefully overwrite) your controller and views and skip the migration.
rails generate mycontroller new create update edit destroy index show --migration=false --skip -f
We're going to add a string column to MyModel
rails generate migration add_[my_column]_to_[mymodel] my_column:string
rake db:migrate
-
Devise is great for creating a user authentication system. If you need signup, log in, log out and sign out, Devise is perfect for your eneds.
-
Jade Templates are easier to work with than
erb
andslim
. This is a personal preference but I also prefer Jade because it works with Node and ExpressJS. -
Administration: If you need a complicated user system with permissions and governance.
Cancan
,pundit
,rolify
are very popular. -
Installing a gem
bundle install