2つの選択タグを持つRails 4アプリケーションでフォームを作成しようとしています。 1つはカテゴリ用で、もう1つはサブカテゴリ用です。サブカテゴリのオプションは、カテゴリの選択によって決定されます。私もとヘルパー持っRails - カテゴリとサブカテゴリのセレクトメニューの設定
<div class="nested-fields">
<div class="container-fluid">
<div class="form-inputs">
<%= f.input :irrelevant, :as => :boolean, :label => "Is an ethics review required or applicable to this project?" %>
<%= f.input :category, collection: [ "Risk of harm", "Informed consent", "Anonymity and Confidentiality", "Deceptive practices", "Right to withdraw"], :label => "Principle", prompt: 'select' %>
<%= f.input :subcategory, collection: text_for_subcategory(@category), :label => "Subcategory", prompt: 'select' %>
</div>
</div>
</div>
:私はこのフォームを持っている瞬間
私はこれをしようと関係なく、私は、カテゴリフィールドでの選択の、
module EthicsHelper
def text_for_subcategory(category)
if category == 'Risk of harm'
[ "Physical Harm", "Psychological distress or discomfort", "Social disadvantage", "Harm to participants", "Financial status", "Privacy"]
elsif category == 'Informed consent'
["Explanation of research", "Explanation of participant's role in research"]
elsif category == 'Anonymity and Confidentiality'
["Remove identifiers", "Use proxies", "Disclosure for limited purposes"]
elsif category == 'Deceptive practices'
["Feasibility"]
else category == 'Right to withdraw'
["Right to withdraw from participation in the project"]
end
end
end
を、サブカテゴリフィールドには、最後の属性のみ(取り消す権利)が設定されます。
私が上記で行ったことに何か問題があり、それが何であるか把握できません。
誰かが間違っているのを誰でも見ることができますか?
この機能を追加するにはJavaScriptを使用する必要があります。 – webster
@rahul - あなたはそれについてどうやって行くべきかについてのガイダンスはありますか? – Mel
下記の私の答えを見つける。 – webster