Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Ruby控制器调用模型_Mysql_Ruby On Rails_Ruby_Rvm_Bundler - Fatal编程技术网

Mysql Ruby控制器调用模型

Mysql Ruby控制器调用模型,mysql,ruby-on-rails,ruby,rvm,bundler,Mysql,Ruby On Rails,Ruby,Rvm,Bundler,我是Ruby的新手,我有一个问题。我正在尝试让一个控制器调用一个模型类来查询MySQL数据库 正确的设置方法是什么?我尽量不使用脚手架,这样我就学会了如何用手来做这件事 class MyController

我是Ruby的新手,我有一个问题。我正在尝试让一个控制器调用一个模型类来查询MySQL数据库

正确的设置方法是什么?我尽量不使用脚手架,这样我就学会了如何用手来做这件事

class MyControllerclass MyController < ApplicationController
  def index
    @post = Post.find(params[:id])
  end
end
def索引 @post=post.find(参数[:id]) 结束 结束
当调用index时,您将在数据库中找到post,它的id等于paramater中给定的id(http://localhost/my_controllers/id)

你能举一个更具体的例子来说明你想要什么吗?rails有很好的文档和很多很容易理解的教程。以“rails入门”为例。