作者GoOdGaMe (GG)
看板Ruby
标题[问题] 初学ruby on rails遇到的问题
时间Fri Mar 13 18:48:26 2009
最近开始学习ruby,有了一些基础的概念,同时也接触了rails
买了圣经来看,虽然rails新版本的一些方法已不同於书上所写的
不过为了练习,就先使用之前的版本来操作
有个问题想请教各位版友前辈
例如在练习scaffold时,知道scaffold 已经为controller建制了8个action
但我要再去了解controller档中这些action程式码的意思,常常会感到吃力
甚至没办法理解这些程式码所表达的意思
例如用这个指令 ruby script/generate scaffold product admin
产生以下controller程式码:
class AdminController < ApplicationController
def index
list
render :action => 'list'
end
# GETs should be safe (see
http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@product_pages, @products = paginate :products, :per_page => 10
end
def show
@product = Product.find(params[:id])
end
def new
@product = Product.new
end
def create
@product = Product.new(params[:product])
if @product.save
flash[:notice] = 'Product was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update_attributes(params[:product])
flash[:notice] = 'Product was successfully updated.'
redirect_to :action => 'show', :id => @product
else
render :action => 'edit'
end
end
def destroy
Product.find(params[:id]).destroy
redirect_to :action => 'list'
end
end
抱歉贴了一大串
其中基本的变数、def方法宣告、for回圈等方法我是看得懂的
不过像是下面者种,我就无法了解他的意思
例如:
def list
@product_pages, @products = paginate :products, :per_page => 10
end
def show
@product = Product.find(params[:id])
end
我有买了向ruby之父学程式这本ruby教学书来看
不过也找不到上面这种类似语句的范例教学
所以我想请问各位前辈 如果要了解这些程式码的意思
我该从哪个方向来加强呢?
能不能提供小弟一个方向或是参考的书目或是网站
因为我觉得学习ruby on rails是一件快乐的事
只是目前卡关了 所以想请大家帮帮忙 先谢谢大家了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.162.55.7
1F:推 godfat:不管问几次,我还是推荐 Programming Ruby... XD 03/13 19:02
2F:→ godfat:不过要买的话,我会建议先看网路的,等 3 版出再买 3 版 03/13 19:03
3F:→ GoOdGaMe:了解 那我就从这本开始看起罗 03/13 23:57
5F:推 deva:你的问题,在 Agile Web Development with Rails 2/e 有解答 03/15 19:25
6F:推 janyfor:list 找出所有资料 一次列出10笔 show 找出id的资料 03/16 00:16
7F:推 fayhong:Ruby for Rails 也不错用 :) 03/19 20:30