Y
Y
Yauheni Dakuka2015-08-05 01:28:45
Ruby on Rails
Yauheni Dakuka, 2015-08-05 01:28:45

How to call a method from a controller without a redirect?

There is a code:

= link_to "Start test", "start_new_test", class: "btn btn-primary"

How to rewrite it so that the "start_new_test" method from the controller is simply called and does not redirect anywhere?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TyzhSysAdmin, 2015-08-05
@ydakuka

As Dima wrote , it's enough just to add remote: true
it. But in the controller, in turn, you need to render the thread, or by default the controller will look for controller_name.html.erb.
In the controller you need to add
If pressing a button still requires some kind of visual reaction, then check out this page rusrails.ru/working-with-javascript-in-rails

D
Dima, 2015-08-05
@MAXOPKA

I understand that you need to make an ajax request.
To do this, put the jquery-ujs gem, and make the helper call like this:

= link_to "Start test", "start_new_test", class: "btn btn-primary", remote: true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question