forked from codecurious-bln/basic-curriculum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordpress-step-4.html
39 lines (34 loc) · 2.26 KB
/
wordpress-step-4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<h2 class="brush:css"><span style="color: #b33605;">Step 4: Adding picture uploads</span></h2>
We need to install additional library to add image processing. Open <strong>Gemfile</strong> in the project and add
<pre class="brush:ruby">gem 'carrierwave'</pre>
under the line
<pre class="brush:ruby">gem 'sqlite3'</pre>
<code></code>
<span style="color: #b33605;"> <strong>Coach: Tell what libraries are and why they are used. Maybe few words about Open Source?</strong></span>
Now we generate the needed code for picture handling.
In the Terminal/Command Prompt run:
<pre class="brush:shell">bundle</pre>
At this point you need to restart the Rails server process in Terminal/Command Prompt. This is needed for the app to load the added gem.
Then you can start adding the picture upload by running a command:
<pre class="brush:shell">rails generate uploader Picture</pre>
Open <strong>app/models/attendee.rb </strong>and add
<pre class="brush:ruby">mount_uploader :picture, PictureUploader</pre>
under the line
<pre class="brush:ruby">class Attendee < ActiveRecord::Base</pre>
Open <strong>app/views/attendees/_form.html.erb</strong> and change
<pre class="brush:xml"><%= f.text_field :picture %></pre>
to
<pre class="brush:css"><%= f.file_field :picture %></pre>
and
<pre class="brush:xml"><%= form_for(@attendee) do |f| %></pre>
to
<pre class="brush:xml"><%= form_for(@attendee, :html => {:multipart => true}) do |f| %></pre>
The view doesn’t look nice, it only shows a path to the file, so let’s fix it.
Open <strong>app/views/attendees/show.html.erb</strong> and change
<pre class="brush:xml"><%= @attendee.picture %></pre>
to
<pre class="brush:xml"><%= image_tag(@attendee.picture_url, :width => 600) if @attendee.picture.present? %></pre>
<span style="color: #b33605;"><strong>Coach: Talk a little about HTML.</strong></span>
<h2 style="text-align: center;"><strong><a href="/apptutorial/rails-girls-app-tutorial-step-4/rails-girls-app-tutorial-step-3/"> < Step 3</a><span style="color: #d33605;">
</span></strong><a style="text-align: right;" href="/apptutorial/rails-girls-app-tutorial-step-4/rails-girls-app-tutorial-step-5/"><strong><span style="color: #d33605;">Step 5 ></span></strong></a>
</h2>