on your Terminal :

run :

1.rails new blog

>you should have ; pcname@pcname-:~$

cd blog/

2. rails generate scaffold Article title:string content:text date:datetime

3. rails generate scaffold Comments content:title date:datetime

>cd ..   then  subl blog after that cd blog

On the open sublime text, go to; config >routes.rb

resources :articles do

                   resources :comments

end
                   root’articles#index’

save the changes

On the Terminal, run:

rails generate migration add_articles_to_comments articles_id:interger

rails server

On the browser go to local host :3000

check that it is able to run to this point with a page that has  Articles, Contents, Date

On the Sublime Text, go to app > models >comment.rb

add belongs_to_article under the class

then  go to: app > models > articles.rb

add has_many_comments under the class

4. go to config >routes.rb

resources :articles do

                   resources :comments

end

On the Terminal, run:

5.rake routes

On the Sublime Text;

6. go to app > views >Articles >show html.erb >

add :

add comment

<%= form_for ([@article, @article.comments.build]) do |f| %>

<%= f.label :content %>

<%= f.text_area :content %>

<%= f.submit %>

<% end %>

(procedure 6 could be copy-pasted  from app >views > comments > form.html.erb )

7. go to app > controllers >comments_controllers.rb

add :

def create
@article =Article.find(params[:article_id])
@comment = @article.comments.create(params[:comment].permit(:content))
redirect_to article_path(@article)
end

on the Terminal, install ;

gem install twitter-bootstrap-rails

rails generate bootstrap ;install less -rails

rails generate bootstrap : layout

<><><><><><><><><><><><><><><><><><><><><><>

gemfile > Add “gem ‘devise'”

terminal > “bundle install”

terminal > “rails generate devise:install”

terminal > “rails generate devise:views”

terminal > “rails generate devise User”

terminal > “rake db:migrate”

terminal > “rake routes” – gives us all available routes from where you get all your routing needs from

app/views/layouts/application.html.erb > change Link 1 to link to ‘new_user_registration_path’

github > create repo ‘dummy-blog’
terminal > git init
> git remore add origin “copy-paste repo link”
> git add .
> git commit -am “sign-up added”
> git push origin master

/views/layout > New File ‘_navigation.html.erb’

/layouts/application.html.erb > type  “<%= render “layouts/navigation” %>” aroud line 5 there. Delete everything inside

<%= render “layouts/navigation” %>

H.E.R.O.K.U
heroku.com > create new account

terminal > wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

> heroku login

> heroku create

gemfile     > after the “group :doc” block, add the block below

“group :production do
gem ‘pg’
gem ‘thin’
end”

> put “gem ‘sqlite3′” at the top of the file in a “group :development do” block after which it will look like below

“group :development do
gem ‘sqlite3’
end”

terminal > bundle update

> gem install pg -v ‘0.17.0

> git push origin master

> git push heroku master

Acknowledgement  to the entire Nairobi Developers School,

Special  contributions from @NjeriChelimo, @njirap and @kevblak.

Advertisements