Reputation: 45
I have a simple form, with a select tag, with options for the select. I want to be able to list those selected options on a view. The only way I know how to do this, would be to call the instance variable that has ActionItem.new(action_item_params) in it, with an attribute as the method (in this case, :purpose). In the view, this displays nothing, where I'd like it to display the select tag option the user selected. - New to OOP, Ruby, and Rails - likely a rookie situation. Will read face off in the meantime.
Form:
<div align="center"><h1><%= @client_name.name %></h1></div></br></br>
<div align="center"><strong>Communication Options:</strong></br></br>
<%= form_for(:action_item, url: {controller: "action_item", action: "create"} ) do |f| %>
<%= f.label("Purpose Of This Contact?:") %>
<%= select_tag(:purpose, options_for_select([['Initial conversation/pitch', 1], ['Follow up correspondence', 2], ['Additional selling point', 3], ['New benefits to convey', 4]])) %></br></br>
<%= f.label("Method Of Correspondence:") %>
<%= select_tag(:correspondence_method, options_for_select([['Send an email', 1], ['Tweet on Twitter', 2], ['Make a phone call', 3], ['Send direct mail', 4]])) %></br></br>
<%= f.label("Do I know the contact person? ") %>
<%= select_tag(:know_person, options_for_select([['Yes', 1], ['No (have to find out)', 2]])) %></br></br>
<%= f.label("this field will be added, ONLY if above field is NO: How could you find the contact's name?") %></br>
<%= f.text_field(:contact_name_answer, :size => 50) %></br></br>
<%= f.label("Additional notes") %></br>
<%= f.text_field(:additional_notes, :size => 50) %></br></br>
<%= f.submit("Store Action Item") %></br></br>
<% end %>
And the show page:
<h1>Action Item: </h1>
Added: <strong><%= @action_submission.additional_notes %></strong>, nice job.</br> </br>
Added: <strong><%= @action_submission.contact_name_answer %></strong></br></br>
Added: <strong><%= @action_submission.correspondence_method%></strong></br></br>
Upvotes: 0
Views: 1878
Reputation: 45
I actually found the answer to be: Just use 1 array, rather than an array of arrays. Now, the array looks like:
<%= f.select(:purpose, ['Initial conversation/pitch', 'Follow up correspondence', 'Additional selling point', 'New benefits to convey']) %></br></br>
This worked just fine. Thanks for reading anyway!
Upvotes: 1