複数選択可能なリストを作りたかったのですがこんなエラーが出てしまいました。
NoMethodError (undefined method each' for "Windows":String): app/controllers/tikka_controller.rb:8:in
index'
色々と調べ実行しましたが解決しませんでしたので質問させていただきました。
ご享受お願いします。
controller.rbの全文
lang
1class TikkaController < ApplicationController 2 3 def index 4 if request.post? then 5 @title = "Result" 6 if params["s1"] then 7 @msg = "you selected: " 8 for val in params["s1"] 9 @msg += val + " " 10 end 11 else 12 @msg = "not selected." 13 end 14 else 15 @title = "index" 16 @msg = "select radio button..." 17 end 18 end 19 20end 21
index.html.erbの全文
lang
1<h1><%= @title %></h1> 2<p><%= @msg %></p> 3<%= form_tag(controller: "tikka",action: "index") do %> 4 <%= select_tag("s1", 5 options_for_select(["Windows", "macOS", "Linux"])) %> 6 {size:5, multiple:true} %> 7 <%= submit_tag("Click") %> 8<% end %> 9
追記
エラー全文
lang
1Started POST "/tikka/index" for 127.0.0.1 at 2017-11-04 19:54:26 +0900 2Processing by TikkaController#index as HTML 3 Parameters: {"utf8"=>"✓", "authenticity_token"=>"Zk62/6Zv6hHJsF/FbywzJhYa0Nc2na5IHK0S2RsGbJqnXxb1rW40zKzkzSorcJ+21hJZIz/JN/NbFmlepB/9TQ==", "s1"=>"Windows", "commit"=>"Click"} 4Completed 500 Internal Server Error in 1ms 5 6 7 8NoMethodError (undefined method `each' for "Windows":String): 9 10app/controllers/tikka_controller.rb:8:in `index'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/05 02:09 編集