MVC framework.
Model: database.
View: decides how the webpage should be shown.
Controller: It coordinates the interaction between the user, the view, and the model.
1. Fire up ruby:
$ rails g controller home index
g means generate.
inside db/migrate folder, there should be one create_building file.
2. then, write down information about this database table:
inclass CreateBuildings < ActiveRecord::Migration
def change
create_table :buildings do |t|
name of the building t.string :building_name
빌딩층수 t.integer :building_story
빌딩주소 t.string :building_address
t.timestamps null: false
end
end
end
3. do rake db:migrate on bash
4. make a simple form on html:
<form action="/upload_building" method="post">
Building name: <input type = "text" name = "building_nme"></input>
Building story: <input type = "text" name = "building_stry"></input>
Building address: <input type = "text" name = "building_addr"></input>
<form>
<button type = "submit" name = "submit" ></button>
5. modify the route file in config folder. the route file coordinates the interaction between files.
just add "post 'upload_building' => 'home#upload_bld'" to the routes.rb file.
This means 'find upload_bld function in home directory'.
6. go to /app/controllers/concerns/application_controller.... and just # protect_from_forgery with: :exception.
7. define the upload_bld function in home_controller.rb.
def upload_bld
bld = Building.new
bld.building_name = params[:building_nm]
bld.building_story = params[:building_stry]
bld.building_address = params[:building_addrs]
bld.save
redirect_to "/home/index"
end
8. devise a way to confirm that the data is recorded in the config/routes.rb file.
def index
@buildings = Building.all
end
9. get the codes written in html file (index.html.erb)
<% @inputResult.each do |b| %>
<%= b.building_name %></br>
<%= b.building_story %></br>
<%= b.building_address %></br>
<% end %>
10. try typing the data in, and see the result from the webpage.
Model: database.
View: decides how the webpage should be shown.
Controller: It coordinates the interaction between the user, the view, and the model.
1. Fire up ruby:
$ rails g controller home index
g means generate.
inside db/migrate folder, there should be one create_building file.
2. then, write down information about this database table:
inclass CreateBuildings < ActiveRecord::Migration
def change
create_table :buildings do |t|
name of the building t.string :building_name
빌딩층수 t.integer :building_story
빌딩주소 t.string :building_address
t.timestamps null: false
end
end
end
3. do rake db:migrate on bash
4. make a simple form on html:
<form action="/upload_building" method="post">
Building name: <input type = "text" name = "building_nme"></input>
Building story: <input type = "text" name = "building_stry"></input>
Building address: <input type = "text" name = "building_addr"></input>
<form>
<button type = "submit" name = "submit" ></button>
5. modify the route file in config folder. the route file coordinates the interaction between files.
just add "post 'upload_building' => 'home#upload_bld'" to the routes.rb file.
This means 'find upload_bld function in home directory'.
6. go to /app/controllers/concerns/application_controller.... and just # protect_from_forgery with: :exception.
7. define the upload_bld function in home_controller.rb.
def upload_bld
bld = Building.new
bld.building_name = params[:building_nm]
bld.building_story = params[:building_stry]
bld.building_address = params[:building_addrs]
bld.save
redirect_to "/home/index"
end
8. devise a way to confirm that the data is recorded in the config/routes.rb file.
def index
@buildings = Building.all
end
9. get the codes written in html file (index.html.erb)
<% @inputResult.each do |b| %>
<%= b.building_name %></br>
<%= b.building_story %></br>
<%= b.building_address %></br>
<% end %>
10. try typing the data in, and see the result from the webpage.