我是 Ruby 新手,我有一个问题。我试图让一个 Controller 调用一个模型类来查询 MySQL 数据库。
正确的设置方法是什么?我尽量不使用脚手架,以便学习如何手动完成此操作。
最佳答案
class MyController < ApplicationController
def index
@post = Post.find(params[:id])
end
end
调用index时,你会在数据库中找到post,其id等于参数中给定的id(http://localhost/my_controllers/id)
关于mysql - Ruby Controller 调用模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5863193/