vendredi 3 avril 2015

If statement in Rails with Simple Form

Im using simple form with my Rails 4 app.


I have a projects model, a scope model and a data model.


Projects accept nested attributes for scopes. Scopes accept nested attributes for data.


In the new project form, I have a question asking users to specify the scope of their project. If they check data as true (being required within the scope), then I want to show another set of questions about the data.


In my new projects form I have this question (nested for scopes) to check whether the project scope includes data:



<%= f.simple_fields_for :scopes do |s| %>
<%= s.input :data, :as => :boolean, :label => false, :inline_label => true %>
<%= s.input :materials, :as => :boolean, :label => false, inline_label: 'Equipment or materials' %>

<% end %>


I then have an if statement, which I want to use to show further questions about the data requirements, if the initial scope question (above) is true. They are in the same form. The attributes for these questions are in the data table:



<% if :data == true %>
<div class="headerquestion-project">Data request</div>

<%= f.simple_fields_for :datum do |d| %>
<% render %>
<%= d.input :prim_sec, label: 'What sort of data do you want?', label_html: {class: 'dataspace'}, collection: ["Primary", "Secondary", "Both" ], prompt: "Choose one" %>
<%= d.input :qual_quant, label: 'Do you need qualitative or quantitative data?', label_html: {class: 'dataspace'}, collection: ["Qualitative", "Quantitative", "Both" ], prompt: "Choose one" %>

<% end %>
<% end %>


I'm thinking this maybe doesn't work because the answer to the initial scope question hasn't yet been saved. Does anyone know how to use an if statement to show the further follow up questions about data, if the initial scope question is answered 'true'?


Thank you


Aucun commentaire:

Enregistrer un commentaire