开发者

Ruby Controllers calling the Model

开发者 https://www.devze.com 2023-03-02 21:55 出处:网络
I am new to Ruby and I开发者_运维知识库 have a question.I am trying to have a controller call a model class which would query a MySQL database.

I am new to Ruby and I开发者_运维知识库 have a question. I am trying to have a controller call a model class which would query a MySQL database.

What is the correct way to set this up? I am trying not to use scaffolding so that I learn how to do this by hand.


class MyController < ApplicationController
  def index
    @post = Post.find(params[:id])
  end
end

when calling index, you will find post in database which id is equal to id given in paramaterer (http://localhost/my_controllers/id)

0

精彩评论

暂无评论...
验证码 换一张
取 消