문제

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>  ) %> 
도움이 되었습니까?

해결책

How about this one-liner with nokogiri? This is just an example

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

You might need to run gem install nokogiri if you don't have nokogiri installed. Write code like this on controller instead of erb file

<% @user = User.find( <I want to grab the above input's value here>  ) %>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top