カテゴリを実装したのですがインスタンス(@item,@categories,@childs)に下記の警告が出ます。どのように修正すれば良いでしょうか
At most two instance variables should be shared between controller and view This inspection warns if there are more than two instance variables shared between a controller and a view. A controller should only manage one instance variable, plus a second one for the current_user variable.
lang
1 2 3<div class="row"> 4 <div class="panel-body form-horizontal payment-form"> 5 <%= form_for(@item) do |f| %> 6 <% if @item.errors.any? %> 7 <div id="error_explanation"> 8 <h2><%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:</h2> 9 10 <ul> 11 <% @item.errors.full_messages.each do |message| %> 12 <li><%= message %></li> 13 <% end %> 14 </ul> 15 </div> 16 <% end %> 17 18 19 20 21 22 <div class="form-group"> 23 <label for="category_id" class="col-sm-3 control-label">カテゴリ</label> 24 <div class="col-sm-9"> 25 <%= f.select :category_id, options_for_select(@categories.collect { |category| 26 [category.name, category.code] }), {:prompt => '選択してください' }, { id: 'category_select' } %> 27 <%= f.select :category_id, options_for_select(@childs.collect { |child| 28 [child.name, child.id] }), {:prompt => '選択してください' }, { id: 'child_select' } %> 29 30 31 32 <script> 33 //$(function () { 34 $(document).on('change', '#category_select', function(evt) { 35 $.ajax({ 36 type: 'GET', 37 url: 'categoreis/list', 38 dataType: 'json', 39 data: { 40 code: $("#category_select option:selected").val() 41 }, 42 error: function(jqXHR, textStatus, errorThrown) { 43 console.log("AJAX Error: " + textStatus); 44 }, 45 success: function(data, textStatus, jqXHR) { 46 $("#child_select").empty(); 47 if (data.length == 0) { 48 $("#child_select").hide(); 49 } else { 50 $("#child_select").show(); 51 } 52 $.each(data, function(idx, item) { 53 // console.log("" + item.code + ":" + item.name); 54 $("#child_select").append('<option value="' + item.code + '">' + item.name + '</option>'); 55 }); 56 console.log("Dynamic country select OK!"); 57 } 58 }); 59 }); 60 // }); 61 </script> 62 </div> 63 </div> 64 65 66 67 <div class="form-group"> 68 <div class="col-sm-12 text-right"> 69 <%= link_to '戻る', items_path, class: 'btn btn-default' %> 70 <%= f.submit '送信', class: 'btn ', data: { disable_with: '送信中…' } %> 71 </div> 72 </div> 73 <% end %> 74 </div> 75</div> 76 77 78
あなたの回答
tips
プレビュー