Steps:
-
Make new Project, test the server.
-
open sublime
-
rails g scaffold title:string body:text
-
rake db:migrate
-
set root path
-
Open rubygems.org and search for devise
-
put devise into the ruby gems
-
bundle install and restart the server
-
rails g devise:install
-
follow the steps by adding the config into the dev rb
-
rails g devise:views
-
rails g devise User
-
rake db:migrate
-
Restart the server and test /users/sign_up
-
rails c and check for User.first
-
show ‘rake routes’ to see what else beside users/ and posts as well
-
Try user_signed_in? in index
-
Try current_user
-
Add links to sign out, sign up, sign in, get them from rake routes
-
rails g migration add_user_id_to_posts user_id:integer:index
-
rake db:migrate
-
add has many and belongs to
-
@user.post.build generates new post with the user_id automatically
-
‘build’ only generate new
-
‘create’ generate new and saves into db
-
update post controller (new and create) methods with @user.posts.build
-
add new post from /posts/new
-
check Post.last.user.email
-
show email in the show html
-
authenticate before action, so only signed in people can create
before_action :authenticate_user!, except: [:show, :index]
-
Rails.Logger = Logger.new(STDOUT)
logger.debug post_params