這是我協會:爲什麼我添加更多模型時突然沒有分配user_id?
class User
has_many :products
has_many :prices
has_many :businesses
has_many :stores
end
class Price
belongs_to :store
belongs_to :user
belongs_to :product
end
class Store
belongs_to :user
belongs_to :business
has_many :prices
end
class Business
belongs_to :user
has_many :stores
end
class Product
belongs_to :user
has_many :prices
end
這是我所做的更改使協會工作正常:
所有型號都在其表user_ID的。
我把上面的關聯放在裏面。
我做了黃燦燦的能力反映這些變化
def initialize(user) if user.role == "admin" can :manage, :all elsif user.role == "default" can :manage, [Price, Store, Business, Product], :user_id => user.id can :read, [Product, Store, Business, Price] end end
我使用的設計,如果它有助於瞭解。
當我想創建一個商業,它讓我但他們沒有分配的用戶。我失去了什麼問題。我以爲它會像以前一樣自動分配自己,因爲用戶只有很多價格。你認爲問題是什麼?
編輯
class BusinessesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
def show
@business = Business.find(params[:id])
end
def new
@business = Business.new
end
def create
@business = Business.new(params[:business])
if @business.save
redirect_to new_business_path, :notice => "Successfully added."
else
render :new, :notice => "It seems there was an error. Please try again."
end
end
end
你跑什麼代碼到cr吃掉生意? – cdesrosiers