我有一个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
提前致谢
答案 0 :(得分: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| %>