Design
Created by Myriam Leggieri, @iammyr for Rails Girls Galway The basic guides that have been merged and adapted are the Ruby on Rails Tutorial, the basic RailsGirls app and the tutorials for creating thumbnails, authenticating users, adding design, deploying to OpenShift and adding comments.
Coach: Talk about the relationship between HTML and Rails. What part of views is HTML and what is Embedded Ruby (ERB)? What is MVC and how does this relate to it? (Models and controllers are responsible for generating the HTML views.)
The app doesn’t look very nice yet. Let’s do something about that. We’ll use the Twitter Bootstrap project to give us nicer styling really easily.
Open app/views/layouts/application.html.erb
in your text editor and above the line
add
and replace
with
Let’s also add a navigation bar and footer to the layout. In the same file, above <div class="container">
add
and before </body>
add
Now let’s also change the styling of the places table. Open app/assets/stylesheets/application.css
and at the bottom add
Now make sure you saved your files and refresh the browser to see what was changed. You can also change the HTML & CSS further.
In case your Terminal shows you an error message that sort of implies there is something wrong with your JavaScript or CoffeeScript, install nodejs. This issue should not appear when you’ve used the RailsInstaller (but when you’ve installed Rails via gem install rails
).
Coach: Talk a little about CSS and layouts.
1.Design your header
-
put the following code to the bottom of
app/assets/stylesheets/application.css
:.navbar { min-height: 38px; background-color: #f55e55; }
Now refresh the page and check the changes. You can try change the color or font of the header. You can check the color reference from http://color.uisdc.com/.
**Coach: ** talk about the property
display
, inline and block element. -
Then put these lines at the bottom:
.navbar a.brand { font-size: 18px; } .navbar a.brand:hover { color: #fff; background-color: transparent; text-decoration: none; }
**Coach: ** explain the 4 states of a link
2.Design your table
-
We simply use the twitter Bootstrap to polish our table。find this line from app/views/places/index.html.erb and replace:
<table>
with
<table class="table">
-
Modify size of the picture using the following lines
<%= image_tag(idea.picture_url, :width => 600) if idea.picture.present? %>
try to change the width and see what’s gonna happen
-
add the following lines to the bottom of file app/assets/stylesheets/places.scss:
.container a:hover {
color: #f55e55;
text-decoration: none;
background-color: rgba(255, 255, 255, 0);
}
- try add some background style with property
background-image
, reference to http://subtlepatterns.com/ for some patterns.
3.add style to footer
-
add the lines to bottom of app/assets/stylesheets/application.css:
footer { background-color: #ebebeb; padding: 30px 0; }
try put more things into
footer
, then adjust it’s position.
4.add style to button
- open
http://localhost:3000/places/new
and find the
Create Place
button.
add these lines to app/assets/stylesheets/places.scss
.container input[type="submit"] {
height: 30px;
font-size: 13px;
background-color: #f55e55;
border: none;
color: #fff;
}
Coach explain how to use border
in css, try modify the style
of button like round the corner, add shadow or color etc.
Open app/views/layouts/application.html.erb
in your text editor and replace the line
with
Open app/assets/stylesheets/application.css
, replace the line
with
Finally, delete the file app/assets/stylesheets/scaffolds.scss
because we don’t really need the default style generated by Rails.
Now refresh the page at http://localhost:3000/places. You will not find much change but it’s good preparation for the following steps.
Considering “place” is the most important object in your app, we are going to put the “New Place” button on the navigation bar to make it always available.
Open app/views/layouts/application.html.erb
, under the line
add
Now it’s time to make the place list page look professional. For that, we are going to replace the table layout with a div layout.
Coach: Talk a little about table vs div.
Open app/views/places/index.html.erb
in your text editor and replace the table with
Coach: Explain what the new code means line by line, and talk a little about Bootstrap 12 grids layout.
Refresh it! We get a nice looking idea list. Click the “New Idea” button, and create more ideas with real text and pretty pictures - the page will look much better with content. There is a principle of contemporary web design: content is the best decoration.
Click the title of a place, and you will be brought to the details page of the place. Now it is still scaffold generated by Rails, so let’s make it better.
Open app/views/places/show.html.erb
in your text editor and replace all lines with
Continue experimenting with Design changes! ;)