Javascript RJS:检索文本字段的值

Javascript RJS:检索文本字段的值,javascript,ruby-on-rails,forms,rjs,ruby-on-rails-2,Javascript,Ruby On Rails,Forms,Rjs,Ruby On Rails 2,我使用的是Rails 2.3,我不知道如何检索表单的text_字段的值,以便在rjs文件中处理它。我在网上搜索了一整天,没有找到解决办法 下面是我更具体的代码: 在my form.erb文件中: <%= observe_field 'issue_'+@issue.id.to_s+'_estimated_hours', :url=>{:action => 'check_estimated_hours_field'}, :with => "'number=' + es

我使用的是Rails 2.3,我不知道如何检索表单的text_字段的值,以便在rjs文件中处理它。我在网上搜索了一整天,没有找到解决办法

下面是我更具体的代码:

在my form.erb文件中:

<%= observe_field 'issue_'+@issue.id.to_s+'_estimated_hours',
  :url=>{:action => 'check_estimated_hours_field'},
  :with => "'number=' + escape(value) + 
        '&fields_estimated_ids=#{@fields_estimated_ids}'" 
%>
检查\u估计\u小时\u字段.rjs:

for @field_id in @fields_estimated_ids
     # here I want to add all the values of fields and retrieve the result in a ruby variable 
end

如何解决我在check\u estimated\u hours\u field.rjs中的评论中遇到的问题?

经过多次测试和研究,显然不可能用rjs恢复表单字段的值。 我找到的解决方案是创建一个包含所有字段值的字符串​​在observe_字段中,将该字符串解析为RJS以检索值​​像这样:

在my form.erb文件中:

<% = observe_field 'issue_' + @issue.id.to_s +'_estimated_hours'
  : url => {: action => 'check_estimated_hours_field'},
  : with => "'number =' + escape (value) +
    '& fields_estimated_values ​​=' + $ ('my_form'). select ('[class ~ = estimated_hours]'). collect (function (n) {
       return n.value + '_';
    }) + "
%>

通过这种方式,我可以添加所有值​​并在变量@total_estimated_hours中检索它们。经过多次测试和研究,显然不可能用RJS恢复表单字段的值。 我找到的解决方案是创建一个包含所有字段值的字符串​​在observe_字段中,将该字符串解析为RJS以检索值​​像这样:

在my form.erb文件中:

<% = observe_field 'issue_' + @issue.id.to_s +'_estimated_hours'
  : url => {: action => 'check_estimated_hours_field'},
  : with => "'number =' + escape (value) +
    '& fields_estimated_values ​​=' + $ ('my_form'). select ('[class ~ = estimated_hours]'). collect (function (n) {
       return n.value + '_';
    }) + "
%>
通过这种方式,我可以添加所有值​​并在变量@total_estimated_hours中检索它们

def check_estimated_hours_field
  estimated_hours_values ​​= params [:estimated_hours_values​​].split('_')
  @total_estimated_hours = 0
  estimated_hours_values.each {| value |
    @total_estimated_hours += hours.to_f
  }
end