0

我有一个 form_for 标签,我想:remote => true根据用户状态启用它的选项

if the current user is not an admin I want the form to be :remote => true
if the current user is an admin I want the form to be a default form

这就是我想出的,它现在不起作用;(

<%= form_for @school, ((:remote => true) unless current_user.admin?) ,  :html => { :class => 'form-horizontal' } do |f| %>

有人能帮我吗

我上线了

ruby 1.9
Rails 3.2.x

提前致谢

4

1 回答 1

0

如何使用具有以下内容的 Helper 方法

def form_remote_or_not(user, object, &block)
    if user.admin?
        form_for object, :remote => true, &block
    else
        form_for object, &block
    end
end

至于您的视图文件;<%= form_remote_or_not(current_user, @school) do |f| %>

于 2012-11-28T21:04:26.170 回答