Rails: textfield list to array of strings
Posted
by poseid
on Stack Overflow
See other posts from Stack Overflow
or by poseid
Published on 2010-04-26T14:01:19Z
Indexed on
2010/04/26
14:03 UTC
Read the original article
Hit count: 213
I want to take input from a textfield and turn it into an array of strings. After having submitted the "post", I want to display again the textfield, but with the array showed below.
I have a view that would look like:
<% form_tag "/list2array" do -%>
<%= text_area_tag "mylist" %>
<div><%= submit_tag 'save' %></div>
<% end -%>
<% @myArray.each do |item| %>
<%= item %>
<% end %>
And as a start for the controller:
class List2ArrayController < ApplicationController
def index
end
def save
@myArray = params[:mylist].split("\r\n")
end
end
However, after the post, I only get an empty textfield without values in the array from the previous POST.
Do I need to use the model layer for my experiment? How? Or do I need to modify my controller?
© Stack Overflow or respective owner