こんにちは。
Rails4の環境において、ActiveRecordのデータが入った変数をjsonに変換したいです。
view上で以下のようにコードを書いています。
<%= @target.class%>
これを実行してActiveRecordが入っていることを確認済みです。
Target::ActiveRecord_Relation
この時に@targetをjsonに変換したいのですが、どのような方法がありますか?
以下のようにすればよいのかと思ったのですが、
<%= @target.to_json.class%>
これを実行したところ、
nil is not a symbol ```となってしまいます。 お分かりになるかた、助けてください。 以上よろしくお願いします。 スタックトレースは以下のように出力されています。 ```ここに言語を入力 Rendered daily_stock_infos/index.html.erb within layouts/application (29.2ms) Completed 500 Internal Server Error in 248ms ActionView::Template::Error (nil is not a symbol): 57: <%= submit_tag 'submit'%> 58: <% end %> 59: 60: <%= @target_stock_detail_list.to_json.class%> 61: 62: <!-- チャート表示 --> 63: <%= hidden_field_tag 'candle_chart_data' ,@target_stock_detail_list %> app/views/daily_stock_infos/index.html.erb:60:in `_app_views_daily_stock_infos_index_html_erb__3924945721297789072_70224501297900' Rendered /opt/ruby/lib/ruby/gems/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.6ms) Rendered /opt/ruby/lib/ruby/gems/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms) Rendered /opt/ruby/lib/ruby/gems/2.1.0/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (9.0ms)
あなたの回答
tips
プレビュー