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> ) %>
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> ) %>
这个带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> ) %>