我是 Ruby on Rails 的初学者,所以我需要一点帮助。我最近开始阅读一个基本教程,它是使用 Scaffolding 教授的。我做了一个“客户端”模型: script/generate scaffold clients name:string ip_address:string speed:integer ... 在 clients_controller.rb 文件中,有一个名为 show 的方法:
# GET /clients/1
# GET /clients/1.xml
def show
@client = Client.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @client }
end
end
对于查询,我会去 localhost:3000/clients/{在此处输入 ID}。不是用 ID 搜索参数,我想用另一个值搜索,比如 ip_address 或 speed,所以我想我所要做的就是在“@client = Client.find(参数 [:id])"。但是,这不起作用,所以请有人告诉我如何使用另一个参数实现搜索。谢谢!