Reputation: 7409
Will remote-true link disable normal javascript code ?
Every product on my page has a remote true(ajax) link
The link will trigger another controller's method
def add_item
product = Product.find_by_id(params["product_id"].to_i)
@cart.add(product, product.price )
end
And I also want to show modal(popup window) when click the link,
But it doesn't work on my Rails.
I think the remote=true break the javascript workflow, right ?
How could I also enable the js remodal popup when click the link ?
What's the better practice, if I want to trigger normal javascript call, and invoke the remote=true
flow at the same time ?
:javascript
window.remodalGlobals = {
namespace: "modal",
defaults: {
hashTracking: false
}
};
%script{:src => asset_path("remodal/jquery.remodal.js", :type => "text/javascript")}
#buy_items.modal{"data-remodal-id" => "contact-modal-success"}
%h1 hihi
= link_to add_item_carts_path(product.id), remote: :true, :class=>"add_to_cart","data-remodal-target" => "contact-modal-success" do
$(document).ready ->
$(".add_to_cart").click ->
alert "hi"
console.log "test"
return
Upvotes: 0
Views: 117
Reputation: 263
I think you can either use JavaScript attribute to hide your HTML tag at first and then animate the showing effect without using the remote: true
or
respond_to do |format|
format.js { something_to_do }
end
might be required for your remote call to js file
Upvotes: 0