3. 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.
7. 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
10. 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
12. 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
15. 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 your
datebase with:
$ rake db:migrate
Now check your posts page in your browesr in the following
link:
$ http://localhost:3000/posts
18. 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
19. score: 000006 XP
Then lets mount our uploader to the Poste Modele
app/models/poste.rb
mount_uploader :picture, PostUploader
Then lets mount our uploader to the Poste Modele
app/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
22. 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#about
controller and add some info there
app/views/pages/about.html.erb
25. 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 css
app/assets/stylesheets/application.scss
@import "bootstrap-sprockets";
@import "bootstrap";
28. 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
29. 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' %>
30. 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 %>