2012-11-28 41 views
0

我有一個的form_for標籤,我想在用戶狀態有條件的form_for標籤+ Rails3中

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 

這使其能夠:remote => true的選擇是什麼,我想出了其沒出息的工作;(

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

可有一個人幫我

我在

ruby 1.9 
Rails 3.2.x 

在此先感謝

回答

0

如何使用一個輔助方法具有以下

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| %>