程序代写代做代考 database WDE-Slides-11.pptx

WDE-Slides-11.pptx

Web System Development with
Ruby on Rails

Day 11(8/Dec/2013)
Project: mini twitter site
Face and ‘Follow’ table

Face table for users
p  Class Name: Face
p  Table Name: faces (plural)
p  1 to 1 relation with users table,

p  User has_one :face
p  Face belongs_to :user

p  Via user.face, if related link from face is
nil, display app/assets/images/
default_face.png file (default icon).

Structure of Face Class
Face Classのフィールド:
user_id, integer (index to User)
name, string (File Name)
content_type, string (MIME type name)
content, blob (content of image files)

Generation of Face Class
Type the following command in 1 line;

rails generate model Face user_id:integer
name:string content_type:string
content:binary

Then, generate the database.
rake db:migrate

Setting up Relations
Add
belongs_to :user

in app/models/face.rb, then add
has_one :face

in app/models/user.rb.

Registration of faces
To register faces, we generate faces

controller which have register action.
rails generate controller faces register

views/faces/register.html.erb

Register Face Photo

<%= form_for @face, :url => “/faces/update”,

:html => {:multipart => true}, :method => :put do %>

User: <%= @user.handle %>

Leave a Reply

Your email address will not be published. Required fields are marked *