2017-04-04 39 views
0

有誰知道如何獲得一個模式,從RoR上的button_tag或submit_tag打開,而不是在提交表單時重定向到另一個頁面?提交RoR模態?

例:

<%= form_tag(compare_products_path, :id => 'product-select', remote: true) do %> 
    <%= button_tag "Compare",id:'compare-button', class: 'pull-right btn btn-default'%> 
    <%= check_box_tag "products[]", product.id %> 

的button_tag應該打開一個模式與產品內容/比較

謝謝!

回答

0

這是一個比較複雜的問題,不知道你的項目是什麼樣的回答,但一般:

您需要提供在控制器方法一個javascript的響應。

def method_here 
    # Other method stuff 
    repsond_to do |format| 
    format.js 
    end 
end 

然後提供與方法的名稱像往常一樣相對應的視圖,只是讓一個.js或者.coffee文件,而不是引入haml或苗條或任何模板,您正在使用。

使用該JS文件觸發模式打開。