2014-08-27 53 views
0

我有問題生成添加和編輯現有用戶的表單。它會生成一個錯誤的URL來提交。我有以下型號:錯誤的URL與simple_form_for

用戶:

class User < ActiveRecord::Base 
    has_many :organization_users, :class_name => "::OrganizationUser", :foreign_key => :user_id, :dependent => :destroy 
    has_many :organizations, :through => :organization_users 

老師:

class User::Teacher < User 

組織:

class Organization < ActiveRecord::Base 
    has_many :organization_users 
    has_many :users, :through => :organization_users 

OrganizationUser:

class OrganizationUser < ActiveRecord::Base 
    belongs_to :user, :class_name => "::User" 
    belongs_to :organization 

在我的路線文件我已經創建下一個規則:

namespace :manager do 
    resources :organizations, :only => [:edit, :update], :controller => "organizations/organizations" do 
      resources :users, :only => [:index, :show, :new, :create, :edit, :update, :destroy] do 
    end 
end 

用戶控制器看起來是這樣的:

class Manager::UsersController < Manager::ApplicationController 
     def new 
     @user = user_scope.new 
     respond_to do |format| 
      format.html 
     end 
     end 
     def edit 
      respond_to do |format| 
       format.html 
      end 
     end 

而且這是我所創建的窗體:

= simple_form_for [:manager, @organization, @user], :as => :user, :html => {:class => 'form-horizontal', :multipart => true} do |f| 
    = f.input :type, :as => :hidden, :input_html => {:name => :type, :value => @type} 
    %ul{:class=>%w(nav nav-tabs)} 
    ...... 

有了這個表格,我可以創建沒有任何問題的新用戶LEM。問題是更新現有的一個,收到此錯誤:

undefined method `manager_organization_user_teacher_path' 

我不知道爲什麼simple_form正在生成與用戶(教師)的鍵入URL,這個路徑不存在。我怎樣才能避免這種行爲?

謝謝!

編輯

在這裏,我表明我是如何加載@user

UserController中:

class Manager::UsersController < Manager::ApplicationController 
    require_power_check 

    power :crud => :users, :as => :user_scope 

    before_filter :load_record, :only => [:show,:edit,:update,:destroy] 

    def load_record 
     @user = user_scope.find(params[:id]) 
    end 

這裏是我的用戶範圍功率:

power :users do 
     types = [] 
     types << 'User::Teacher' if can_organization_teacher_index? 
     types << 'User::Student' if can_organization_student_index? 
     types << 'User::Parent' if can_organization_parent_index? 
     User.active.where("type in  (?)",types).includes(:organization_users).where('organization_users.organization_id'=>@organization) 
    end 

我試着MaximusDominus解決方案,但它的工作很高興知道它爲什麼會發生。

回答