2011-10-05 86 views
4

我在rails 2.3.8上开发项目,我需要在模型对话框中使用observe_field,但它不适用于我。是否可以在模型对话框中使用“observe_field”?请有人能解释我如何在模型对话框中使用它? 这我如何使用观摩申请如何在rails 2.3.8的JQuery模型对话框中使用“observe_field”?

<%= collection_select("event", "trainer_id", @trainers , :id, :name, {:prompt => true}) %> 
<%= link_to_remote 'Show calendar', :url => {:controller => 'calendar', :action => 'dynamicTrainer'} %> 

<%= observe_field 'event', 
:url => {:controller => 'calendar', :action=> 'dynamicTr'}, 
:with => "'mypara=' + escape(value)" %> 

这是在日历控制器dynamicTr方法。

def dynamicTr 
if (defined? (params[:trainer_id])) 
    session[:my123] = 'defined' 
else 
    session[:my123] = 'not' 
end 
end 



def dynamicTrainer 




session[:mySerach]=params[:mypara] 
@month = (params[:month] || (Time.zone || Time).now.month).to_i 
@year = (params[:year] || (Time.zone || Time).now.year).to_i 
@shown_month = Date.civil(@year, @month) 
@trainers=Trainer.all 
@first_day_of_week = 1 

    if session[:mySerach].nil? 
     if (defined? (params[:mypara])) 
      session[:mySerach]=(params[:mypara]) 

      #@@id=(params[:event][:trainer_id]) 
      @event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week, :conditions=>["trainer_id = ?",session[:mySerach]])   
     else 
      @event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week)    
     end 
    else 
     @event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week, :conditions=>["trainer_id = ?",session[:mySerach]])   
    end  
end 

这是我dynamicTrainer.js.rjs文件

page.replace_html 'show_cal', :partial => 'dynamicTr' 

page<< "$j ('#show_cal_dialog').dialog({ 
    title: 'calendar', 
    modal: true, 
    width: 500, 
    height: 500, 
    close: function(event, ui) { $j ('#show_cal_dialog').dialog('destroy') } 

});" 

这是dynamicTr部分代码

<%= stylesheet_link_tag "event_calendar" %> 
<%= event_calendar%> 
<%= session[:my123]%> 

问题是,它显示日历,但它不打印会话值。我不能在模型对话框上使用observe_field?请有人在这里解释我的问题。

回答

4

我认为您的观察区域存在问题。

使用collection_select场的ID在观察现场为 'event_trainer_id'

<%= observe_field 'event_trainer_id, 
:url => {:controller => 'calendar', :action=> 'dynamicTr'}, 
:with => "'mypara=' + escape(value)" %>