lundi 10 avril 2017

Rails how to Render a form instead of redirect on submit?

I have a form that the results just show if render instead of redirect.

so the form must not be redirected. someone know if this is possible with rails?

the form is:

  Pac: <%= @pac %> 
                   Sedex: <%= @sedex %> 
                 <%= form_tag calculate_ship_path, :method => "get" do %>                          
                  <%= text_field_tag :post_code%>

                 <% end %> 

the order controller and action is:

  def calculate_ship
    frete = Correios::Frete::Calculador.new cep_origem: "#{@order.seller.post_code}",
      :peso => "#{@order.product.weight}",
      :comprimento =>  "#{@order.product.weight}",
      :largura =>  "#{@order.product.weight}",
      :altura =>  "#{@order.product.weight}",
      cep_destino: params[:post_code]
    servicos = frete.calcular :sedex, :pac
    @pac = servicos[:pac].valor
    @sedex = servicos[:sedex].valor
    render '/path/to/rails/app//orders/:id/checkout'
  end

and the routes is:

get  '/path/to/rails/app//orders/:id/checkout', to: 'orders#checkout', as: :calculate_ship

Aucun commentaire:

Enregistrer un commentaire