vendredi 24 avril 2015

can not generate html output using rails 3

I have one issue.I am trying to render one select drop down value using rails 3.On the front page(UI) it is coming as per required but when i did view page source and checked it is not there.There is no html output generated but cannot understand how it is coming on UI.Please check my code below.

payment.html.erb:

<%= form_for :payment,:url => {:action => "check_type" },remote: true do |f| %>
    <div class="totalaligndiv">
      <div class="input-group bmargindiv1 col-md-6 pull-left"><span class="input-group-addon text-left"><div class="leftsidetextwidth">Type :</div></span>
      <%= f.select(:s_catagory,options_for_select([['Wood','Wood'],['Puja Samagree','Puja Samagree'],['Sweeper','Sweeper'],['Photo Grapher','Photo Grapher'],['Burning Assistant','Burning Assistant']],selected: "Type"),{},{:class => 'form-control',:onchange => ("$('#switch_car').submit()")}) %>
      </div>
      <div id="div_select" style="display:none">
      <div class="input-group bmargindiv1 col-md-6 pull-left" ><span class="input-group-addon text-left" ><div class="leftsidetextwidth">Select Vendor :</div></span>
      <div id="name-option">

      </div>
      </div>
      </div>
      <div class="clearfix"></div>
      <div class="tbpaddingdiv1 text-center">
        <%= f.submit "submit",:class => "btn btn-success",:id => "switch_car" %>
      </div>
    </div>
    <% end %>

payment_controller.rb:

class PaymentsController < ApplicationController
    def payment
        @payment=Vendor.new
        respond_to do |format|
            format.html 
            format.js
        end

    end
    def check_type
        flash[:notice]=params[:payment][:s_catagory]
        if  params[:payment][:v_name]
            flash[:notice]="hello"
        else
            @payment=Vendor.find_by_s_catagory(params[:payment][:s_catagory])
            @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 %>
console.log('hello');
$("#paymentdetail").css("display", "block");
$("#paymentoption").html("<%= escape_javascript (render 'paymentdetails' ) %>");
$("#paymentoption").slideDown(350);
<% end %>
$(".flash-message").html('<%= escape_javascript flash[:notice] %>');

_nameoption.html.erb:

<%= select_tag(:v_name,options_for_select(@v_name),{:class => "form-control"}) %>

Please help me to resolve this issue because i cannot execute the if part of check_type method in controller action.

Aucun commentaire:

Enregistrer un commentaire