Reputation: 653
I have a form and on the submit, it directs to a 'overlap_check' controller action. In the action, if a condition is met from the params that have been sent, i want to render a modal on the page by calling a javascript function. Is this possible?
I've seen some examples using:
# render :js => "('#testing').modal('show');"
But no luck with this.
thanks
Upvotes: 2
Views: 1608
Reputation: 521
Please mention below format in controller action.
respond_to do |format|
format.js
end
And create actioname.js.erb
in views. There you can call ('#testing').modal('show');
.
If you calling controller action by link then add remote: true
<%= link_to your_link_name, path, :remote => true %>
Or If you calling from action then add remote: true
in your form
Then it should be work.
Upvotes: 0
Reputation: 4709
1) in controller:
def overlap_check
respond_to do |format|
format.js
end
end
2) create overlap_check.js.erb
3) add js code to overlap_check.js.erb
('#testing').modal('show');
4) add remote: true
to form
Upvotes: 2