Ruby on rails3 - introduction to rails

729 views

Published on

introduction to ruby on rails, creating a blog

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
729
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
13
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Ruby on rails3 - introduction to rails

  1. 1. One word … Beautiful
  2. 2.  Rails is a web application developmentframework written in the Ruby language. It isdesigned to make programming webapplications easier by making assumptionsabout what every developer needs to getstarted.
  3. 3.  DRY – “Don’t Repeat Yourself” Convention Over REST is the best pattern for web applications
  4. 4.  Rails installer Aaaaaaand it is done Update using Gem update --system Gem update
  5. 5.  Model : Data layer Views : Presentation layer Controller : Linking between mode and views
  6. 6. rails new blog
  7. 7.  cd blog rails server localhost:3000
  8. 8.  Delete public/index.html Generate index page rails generate controller home index set homepage root :to => "home#index"
  9. 9.  Create scaffold along with a model rails generate scaffold post name:stringtitle:string content:text rake db:migrate Add link to home page <%= link_to "My Blog", posts_path %>
  10. 10.  validates :name, :presence => true validates :title, :presence => true, :length=> { :minimum => 5 }
  11. 11.  Create model rails generate model comment commenter:stringbody:text post:references rake db:migrate Add repation to post model has_many :comments Add it as subresource to post resources :posts do resources :comments end Create controller rails generate controller Comments
  12. 12.  Add a comment: <%= form_for([@post,@post.comments.build]) do |f| %> <%= f.label :commenter %> <%= f.text_field :commenter %> <%= f.label :body %> <%= f.text_area :body %> <%= f.submit %> <% end %>
  13. 13.  @post = Post.find(params[:post_id]) @comment =@post.comments.create(params[:comment]) redirect_to post_path(@post)
  14. 14.  <h2>Comments</h2> <% @post.comments.each do |comment| %> Commenter: <%= comment.commenter %> Comment: <%= comment.body %> <br/> <% end %>
  15. 15.  Add user name and password http_basic_authenticate_with :name => “admin",:password => “admin", :except => [:index, :show]
  16. 16.  Tags Comments moderation Images for post Attached youtube video to post Posts categories … what else ?
  17. 17.  Implement new ideas with your team Read http://haml.info/tutorial.html http://haml.info/docs/yardoc/file.REFERENCE.html

×