I do not recharge the page ruby on rails

1

Hi, I want that when the boolean changes to true and I save it again and I recharge the page, but it turns out that I do not reload it, thanks for the help. auto is boolean

MeetingsController

def auto1
  r = Reunion.find(params[:id])
  r.auto = true
  r.valid?
  p r.errors
  r.save(validate: false)
  respond_to do |format|
  format.json { render :show}
  end   
 end

routes.rb

 get 'reuniones/:id/auto1' => 'reuniones#auto1', as: :auto1

show.html.erb

<% if @reunion.auto == nil  %>
  <%= link_to 'Autorizar', auto1_path(@reunion.id),remote:true %>
<% end %>
    
asked by MIGUEL ANGEL GIL RODRIGUEZ 06.10.2017 в 05:08
source

1 answer

2

If you want to reload the page you do not need AJAX , simply use redirect_to (in HTML ) to reload the page:

meetings_controller.rb :

def auto1
  r = Reunion.find(params[:id])
  r.auto = true
  r.valid?
  p r.errors
  r.save(validate: false)

  redirect_to action: "show", id: r.id
end

We remove format (since it is no longer necessary) and we simply leave redirect_to :show , which will make the page show.html.erb load again; it is important to note the use of redirect_to instead of render , which will process the complete action ( show ), thus generating the variables required by the view.

show.html.erb :

<% if @reunion.auto == nil  %>
  <%= link_to 'Autorizar', auto1_path(@reunion.id) %>
<% end %>

We simply remove remote: true so that it is not an AJAX request.

    
answered by 06.10.2017 / 15:20
source