开发者

How to get data from input field using ruby on rails

How to get data from an HTML text field and use it in RoR?

For example, let's say I enter a word in t开发者_StackOverflow中文版he text field and RoR prints how many characters are in said word.


Best way to do that is using the JAVASCRIPT but you insist for ROR use observe_field

<%= text_field  :users, :word, :value=>'',  :autocomplete=>'off' %><br>
<span id="word_message" style="color :red; font-size: 9px;"></span>
<%= observe_field  :users_word,  :url => {  :action =>  :word_length,  :id=>1 },
               :on=>"blur",
               :frequency => 0.25,
               :with => "'word='+value" %>

In Controller

def word_length
  word = params[:word]
  render :update do |page|
    page.replace_html  'word_message', "#{word.length} characters"
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜