如何在RoR中使用observer_field?

时间:2010-06-12 18:55:45

标签: ruby-on-rails

我有一个select_tag,其中包含从控制器中的数组收集的类别。当用户选择类别时,我希望应用程序重定向到所选类别。我在视图中有以下代码。 (我已尝试使用:method =>:get and:post,只有更改在development.log中)

<%=select_tag "cat_selected", options_for_select(@cats_for_mt)%><br>
<%=observe_field 'cat_selected',
  :url => {:action => :viewflokkur},
  :with => 'cat',
  :method => :get %>

当我选择其中一个选项时,以下内容将记录到development.log。

Processing CategoriesController#viewflokkur (for 127.0.0.1 at 2010-06-12 12:33:26) [GET]
Parameters: {"cat"=>"Taugasjúkraþjálfun", "authenticity_token"=> "B2u5ULNr7IJ/ta0+hiAMBjmjEtTtc/yMAQQvSxFn2d0="}
Rendering template within layouts/main
Rendering categories/viewflokkur
Completed in 20ms (View: 18, DB: 0) | 200 OK [http://localhost/categories/viewflokkur?cat=Taugasj%C3%BAkra%C3%BEj%C3%A1lfun&authenticity_token=B2u5ULNr7IJ%2Fta0%2BhiAMBjmjEtTtc%2FyMAQQvSxFn2d0%3D]

根据这个,我现在应该在“viewflokkur”中,但浏览器窗口中没有任何变化。还有什么我需要做的,也许在控制器中?

BR,
辛德里

1 个答案:

答案 0 :(得分:0)

以下是观察字段的示例:

<label for="search">Search term:</label> 
<%= text_field_tag :search %> 
<%= observe_field(:search, 
              :frequency => 0.5, 
              :update => :results, 
              :url => { :action => :search }) %> 
<div id="results"></div>

找到here