Users have many websites, and Websites have many Keywords. (Keywords being nested resources of the Websites resource)
Right now, with the default scaffolding setup, it’s very tedious to add many keywords at once. I’d like a text area instead of a text field that allows users to type many keywords, each on their own line, and submit them all at once. The only input on the form is for the keyword’s “text” column.
How can I do this?
I can figure out things like params[:keyword][:text].split("\r\n").each do |text|, but I’m not sure how to interact it with the Rails form.
<%= form_for [@website, @keyword] do |f| %>
<% if @keyword.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@keyword.errors.count, "error") %> prohibited this keyword from being saved:</h2>
<ul>
<% @keyword.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :text %><br />
<%= f.text_area :text %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
(Note: I originally stuck this on the original post as an edit, so I’ve instead copy and pasted it so it’s the best answer)
Here’s what I ended up doing in the meanwhile. It’s sloppy (I’m a Ruby noob), but it saves the keywords that are valid and renders back “new” with a list of the failed keywords: