0

乳がん啓発月間 (10 月) には別のロゴを使用したいと思います...10 月までに確実に機能するように、params を使用してロゴをテストしたいと思います。明らかに悪いことをしている!

コントローラ:

def breast_cancer_logo_month
  if params[:breast_cancer_logo_month] || Time.current.month = 10
    return true
  end
  false
end

見る:

<% if breast_cancer_logo_month  %>
  #breast cancer logo
<% else %>
  #standard logo
<% end %>
4

1 に答える 1

4

あなたの Breast_cancer_logo_month は間違っています。2 つ必要な場合は、単純な等号を使用しています。Time.current.month1 つの等しいものは、エラーを発生させるオーバーライド値を試みます。
さらに、条件で true または false を返す場合は、条件を返すだけです。? を追加できます。メソッド名にも。

def breast_cancer_logo_month?
  !!params[:breast_cancer_logo_month] || Time.current.month == 10
end

<% if breast_cancer_logo_month? %>
  #breast cancer logo
<% else %>
  #standard logo
<% end %>
于 2012-09-21T02:42:14.773 に答える