-1

したがって、引用モデルから変数の 1 つにアクセスしたいと思います。

class Quotes < ActiveRecord::Base
  attr_accessible :quotes1, :quotes10, :quotes2, :quotes3, :quotes4, :quotes5, :quotes6, :quotes7, :quotes8, :quotes9

  attr_accessor :quotes1, :quotes10, :quotes2, :quotes3, :quotes4, :quotes5, :quotes6,   :quotes7, :quotes8, :quotes9
end

でアクセスしたいので、ここに私のページコントローラーがありますviews/pages/home.html.haml

def home
  @quotes = Quotes.find(:first, :order => "RANDOM()")
end

そして、ここに私のものがありますhome.html.haml

%h2
  Client's opinions
%p
  =@quotes

これらの 1 ~ 10 の引用符はすべて文字列であり、デフォルト値があり、nil ではありません。それでも、ホームページには何も表示されません。なんで?

4

1 に答える 1

0

コントローラ:

quotes_number = (srand % 10) + 1
@quotes = Quotes.find(:first, :order => "RANDOM()").send(:"quotes#{quote_number}")

見る:

%h2
  Client's opinions
%p
  =@quotes
于 2013-10-27T13:47:32.650 に答える