是否可以在observe_field帮助器中放入一个条件?

时间:2010-11-10 16:42:17

标签: ruby-on-rails observer-pattern conditional-statements

使用observe_field助手,我正在保存数据并在更新时使微调器可见。另外,我想更新一个div。可以用observe_field助手里面的条件来完成吗?

<%= observe_field 'act_feb',
    :url => { :controller => :prep, :action => :toggle_feb },
    :method => :put,
    :loading => "$('feb_spinner').setStyle({visibility: 'visible'});",
    :complete => "$('feb_spinner').setStyle({visibility: 'hidden'});",
    :with => "'feb=' + $('act_feb').value",

    if $('team_feb').value == true
        "$('jan_reminder_').setStyle({visibility: 'visible'});"
    else
        "$('jan_reminder_').setStyle({visibility: 'hidden'});"
    end %>

1 个答案:

答案 0 :(得分:0)

我可以看到它处于错误的位置。如果我将它放在“:完成”后怎么办?

<%= observe_field 'act_feb',
    :url => { :controller => :prep, :action => :toggle_feb },
    :method => :put,
    :with => "'feb=' + $('act_feb').value",
    :loading => "$('feb_spinner').setStyle({visibility: 'visible'});",
    :complete => "$('feb_spinner').setStyle({visibility: 'hidden'});
    if $('team_feb').value == true
        $('jan_reminder_').setStyle({visibility: 'visible'});
    else
        $('jan_reminder_').setStyle({visibility: 'hidden'});
    end" %>