0

:remote => trueform_for タグがあり、ユーザーのステータスに応じてそのオプションを有効にしたい

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

次のヘルパーメソッドを使用するのはどうですか

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 に答える