Ruby On Rails Starter Kit
-
Upload
el-orabi-mohamed-ikbal -
Category
Technology
-
view
211 -
download
0
Transcript of Ruby On Rails Starter Kit
Start
Ruby On Rails Starter KIT
score: 000000 XP
Level #1
Introduction
score: 000000 XP
What is ruby?
Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.Matsumoto has said that Ruby is designed for programmer productivity and fun, following the principles of good user interface design
What is rails?
Ruby on Rails, or simply Rails, is a web application framework written in Ruby under MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pages.
score: 000000 XP
Controller
ViewModel
+1 XPNew level has been unlocked
Level #2
Installing Rails
score: 000001 XP
Windows:
@RailsInstaller provide package included all what you need to start your first project with Rails ( http://railsinstaller.org )
Linux&Mac:
You can install Rails with RVM (Ruby version manager) with a simple two commands:$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3$ \curl -sSL https://get.rvm.io | bash -s stable --rails
+1 XPNew level has been unlocked
Level #2
Build your first app
score: 000002 XP
You can create a new app called (blog) by running the following CMD:
$ rails new blog
Now we need to change the directory to our Rails App
$ cd blog
start the rails server by running
$ rails s
You can find your app on the following link below:
$ http://localhost:3000
+1 XPNew level has been unlocked
score: 000003 XP
You can create a new app called (blog) by running the following CMD:
$ rails new blog
Now we need to change the directory to our Rails App
$ cd blog
start the rails server by running
$ rails s
You can find your app on the following link below:
$ http://localhost:3000
+1 XPNew level has been unlocked
Level #3
Start Scaffolding now
score: 000004 XP
So to make it easier creating CRUD system there is something called scaffolding, rails have the philosophy of DRY so this will save your time
$ rails generate scaffold post title:string content:text picture:string
Each time you create a model in rails you should migrate yourdatebase with:
$ rake db:migrate
Now check your posts page in your browesr in the followinglink:
$ http://localhost:3000/posts
+2 XPNew level has been unlocked
Level #4
Upload Pictures
score: 000006 XP
Firstable lets Open up the Gemfile wish is located in the root directory of your app and add this line:
gem 'carrierwave'
Then install the Carrierwave gem:
$ bundle install
After installing the Carrierwave gem now you should create your first Uploader, this will create picture_uploader.rb file in app/uploaders
$ rails generate uploader Picture
score: 000006 XP
Then lets mount our uploader to the Poste Modeleapp/models/poste.rb
mount_uploader :picture, PostUploader
Then lets mount our uploader to the Poste Modeleapp/models/poste.rb
mount_uploader :picture, PostUploader
Now we should update our poste form
<%= f.text_field :picture %><%= f.file_field :picture %>
And we should update the show page also
<%= image_tag(@post.picture_url, :width => 600) if @poste.picture.present? %
:picture
+2 XPNew level has been unlocked
Level #5
Create Static Pages
score: 000008 XP
If you want to create a static page you can do it by creating a controller with the corresponding view
$ rails generate controller pages about
Now you can visit your page through
$ http://localhost:3000/pages/about
Open up the view file corresponding to the pages#aboutcontroller and add some info there
app/views/pages/about.html.erb
+1 XPNew level has been unlocked
Level #6
Bling Bling Baby
score: 000008 XP
Its all up to you to tweek your css file, wich is located in the following path:
app/assets/stylesheets/application.css
If you are planning to use bootstrap so make sure you add bootstrap to your Gemfile
gem 'bootstrap-sass', '~> 3.3.6'
Now Import bootstarp to your main application cssapp/assets/stylesheets/application.scss
@import "bootstrap-sprockets";@import "bootstrap";
+1 XPNew level has been unlocked
Level #7
Make some serious relations
score: 000009 XP
Create a comment scaffold, with the commentator name, the comment body (contents of the comment) and with the reference to the ideas table (post_id).
$ rails g scaffold comment user_name:string body:text post_id:integer
Then migrate your datebase:
rake db:migrate
Openup poste model File app/models/post.rb and add
has_many :comments
score: 000009 XP
And from the comment side add
belongs_to :post
And from the comment side add
<h3>Comments</h3><% @comments.each do |comment| %><div>
<strong><%= comment.user_name %></strong><br /><p><%= comment.body %></p><p><%= link_to 'Delete', comment_path(comment), method: :delete, data: { confirm: 'Are you
sure?' } %></p></div>
<% end %><%= render 'comments/form' %>
score: 000009 XP
Lets modifier the app/controllers/ideas_controller.rb to get fit with what we did in the previously changes
@comments = @idea.comments.all@comment = @idea.comments.build
And also add the following line app/views/comments/_form.html.erb
<%= f.hidden_field :idea_id %>
Congratulation!! you finished all the levels
of the gameWith 10 XP
Now you are ready for another levels of the game but you need extra life points !!
So follow us onFacebook Group Rails on Algeria
FB: El Orabi Mohamed Ikbal [email protected]