`
peryt
  • 浏览: 54420 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery

6.3 make model, view, controller work together.

 
阅读更多

1. let's start to console without --sandbox param to create some record into our database:

 

 

rails console
User.create!(:name => "china zhang", :email => "china@china.com")

 to see if this work, let's use SQLite database browser to see.

 

2. let's create a view named 

 

show.html.erb

 

then create a action in users_controller.rb

 

 

def show
	@user = User.find(params[:id])
end

 

we need to explain sth here, 

 

params is a hash for controller to use:

params[:controller] 

params[:action]

params[:id]

 

debug(params)

is a very useful method, ti will provide useful feedback, and it is very good habit to use it when you have some unexpected things happened.

 

3. we still need route to make things work. we will follow REST architecture.

 

resources :users

 

then you will get this route:   users/1

 

 

4. it is a good timing to git commit your changes:

 

git add .

git commit -m "finished first half of the user model"

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics