使用 Rails 3 获取未定义的局部变量或方法错误

Getting undefined local variable or method error using Rails 3

您好,我在尝试使用 Rails 渲染 table 时遇到以下错误 3.

Error:

ActionView::Template::Error (undefined local variable or method `result' for #<#
<Class:0x3460410>:0x2af4d10>):

我在下面解释我的代码片段。

payments_controller.rb:

class PaymentsController < ApplicationController

    def payment
        @payment=Vendor.new
        respond_to do |format|
            format.html 
            format.js
        end

    end
    def check_type  
        if params[:commit]=="submit"
            @vendor_type = PaymentVendor.where(:v_name => params[:v_name]).map{|v|[v.v_catagory ,v.Receipt_No]}
            #@vendor_type = PaymentVendor.where(:v_name => params[:v_name]).pluck(:v_catagory)
            output=[]
            result=[]
            @vendor_type.each do |i|
              if i.first == params[:payment][:s_catagory]
                output << i[1]
              end  
            end  
            output.each_with_index{|val, index|
               #puts "#{val} => #{index}" 
               #puts output1[index]
               result << PaymentVendor.find_by_Receipt_No(output[index])
               puts "Value of local variable is #{result}"

            }
        else
            @v_name=Vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name)
        end
    end
end

check_type.js.erb:

<% if @v_name %>
$("#div_select").css("display", "block");
$("#name-option").html("<%= escape_javascript (render 'nameoption' ) %>");
$("#name-option").slideDown(350);
<% end %>
<% if @vendor_type  %>
console.log('hello')
$(".flash-message").html('<%= escape_javascript flash[:notice] %>');
$("#paymentdetail").css("display", "block");
$("#paymentoption").html("<%= escape_javascript (render 'paymentdetails' ) %>");
$("#paymentoption").slideDown(350);
<% end %>

_paymentdetails.html.erb:

<div><%= @vendor_type %></div>
        <table class="table table-bordered">
        <colgroup>
            <col class="col-md-1 col-sm-1">
            <col class="col-md-1 col-sm-1">
            <col class="col-md-3 col-sm-3">
            <col class="col-md-3 col-sm-3">
            <col class="col-md-4 col-sm-4">
        </colgroup>
        <thead>
            <tr>
                <th class="text-center"><input type="checkbox"></th>
                <th class="text-center">Sl. No</th>
                <th class="text-center">Date</th>
                <th class="text-center">Receipt No.</th>
                <th class="text-center">Amount</th>
            </tr>
        </thead>
        <tbody>
            <% result.each do |r| %>
            <tr>
                <th class="text-center"><input type="checkbox" id="checkbox1-1" name="checkbox1-1"></th>
                <td class="text-center"><%= r.id %></td>
                <td class="text-center"><%= r.c_date %></td>
                <td class="text-center"><%= r.Receipt_No %></td>
                <td class="text-center"><i class="fa fa-rupee"></i><%= r.v_amount %></td>
            </tr>
            <% end %>
        </tbody>
    </table>

此 table 将在 payment.html.erb 上呈现 page.I 成功呈现空白 table 但我需要在此 [=27] 上显示结果变量中的值=] 帮我解决这个错误。

如果要使 result 在视图中可访问,应将其设为实例变量 (@result)。

resultcheck_type 中本地定义,在视图中无法访问。 在视图和控制器中将其更改为 @result