0

I want to grab an input's value in the html and use it in my ruby code like this. Any ideas?

<input type="hidden" id="useThis" value="1">

<% @user = User.find( <I want to grab the above input's value here>  ) %> 
4

1 回答 1

1

这个带nokogiri的单线怎么样?这只是一个例子

require 'nokogiri'
s = '<input type="hidden" name="currentRackU" id="currentRackU" value="11">'
Nokogiri::XML.parse(s).root.attributes['id'].value # currentRackU

如果您没有安装 nokogiri,您可能需要运行 gem install nokogiri。在控制器而不是 erb 文件上编写这样的代码

<% @user = User.find( <I want to grab the above input's value here>  ) %>
于 2013-10-10T20:17:46.887 回答