Premisse:我對javaScript的瞭解甚少。Rails資產和JavaScript集成
在Rails佈局,下面的腳本功能:
<script>
$(function() {
$("#date_available_dal").datepicker({dateFormat: 'yy-mm-dd', showButtonPanel: true});
$("#date_available_al").datepicker({dateFormat: 'yy-mm-dd', showButtonPanel: true});
});
</script>
但是,如果我把相同的代碼,而剝離開閉腳本標記,在.js文件中的資產/ JavaScript的文件中,瀏覽器加載文件,但[如Curly所說]沒有任何反應。
我在很多場合都遇到過這個問題&它妨礙我正確使用管道。什麼是軌道在後臺做,可能會改變這個腳本的行爲?
在同一個思路,如果我是給定的應用方法
def set_locale
if user_signed_in?
I18n.locale = current_user.idioma.code.downcase
else
I18n.locale = params[:locale] || I18n.default_locale
end
end
的區域追加到
datepicker({dateFormat: 'yy-mm-dd', regional[ #{set_locale} ]
怎麼會變成這樣代碼的燃料電池堆之間如何處理?
更新
目前在開發模式下,瀏覽器接收文件有以下:
$(function() {
$("#date_available_dal").datepicker({dateFormat: 'yy-mm-dd', minDate: 0, numberOfMonths: 3, showButtonPanel: true});
$("#date_available_al").datepicker({dateFormat: 'yy-mm-dd', minDate: 1, numberOfMonths: 3, showButtonPanel: true});
});
堅持一次一個問題。關於第一個問題,您發佈的代碼沒有明顯的錯誤,並且無法說明資產管道在沒有看到輸出的情況下做了什麼。 –
更新了包含代碼的問題。 (是的,關於多個問題的理解,我的假設是它們以某種方式鏈接) – Jerome
您能在瀏覽器控制檯中看到任何腳本錯誤嗎?這些文件中的唯一四行是否傳送給瀏覽器?如何以及何時加載jQuery? –