1

Hi i am getting the following error when trying to render a table using Rails 3.

Error:

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

I am explaining my code snippets below.

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>

This table will render on the payment.html.erb page.I got success to render blank table but i need to show the value within result variable on this table.Please help me to resolve this error.

2 Answers 2

1

If you want to make result accessible in view, you should make it instance variable (@result).

Sign up to request clarification or add additional context in comments.

Comments

0

result is locally defined in check_type its not accessible in view. change it to @result in view and controller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.