我有两个部分形式
_form.html.erb正在嵌入_slider.html.erb,其中包含一个javascript滑块值,如下所示;
onChange: function(v)
{ $('slide').value= v; }
我的问题是:我怎样才能将_slider.html.erb中的'slide'值变为_form.html.erb文件中的rails变量,以便我可以使用
发布该值<%= number_field :score, :obtained_score, :value => **that variable** %>
到我的数据库?
答案 0 :(得分:0)
你的问题的措辞需要改变,因为你不会将javascript变量复制到rails变量,但是一切都将在客户端发生,这意味着它只是javascript。
滑块的onchange事件应该使用以下代码
更新rails生成的DOM中的<input id='model_score' type='number' />
元素
<%= number_field :score, :obtained_score, :value => that variable %>
在滑块的onchange处理程序中执行以下操作
on_slider_change_handler = function(e){
$("#model_score").value = $(this).value; // this will be slider specific code
};