You just need to add foreign key in your existing association class Purchase 'user_purchase_type_id' attr_accessible :date, :user_purchase_type_id, :note end.
You just need to add foreign key in your existing association. Class Purchase 'user_purchase_type_id' attr_accessible :date, :user_purchase_type_id, :note end.
This plus adding belongs_to :user_purchase_type did it, thanks – sopwithpup Sep 28 at 11:39.
Class Purchase UserPurchaseType association is a has_many relationship but you seem to be trying to use it with user_purchase_type_id which would indicate a belongs_to :user_purchase_type relationship, but your association is has_many :user_purchase_types It sounds like you may want something like: #this works to list all your UserPurchaseType typename's, comma separated. If you do this, make sure when you load your @purchases in the controller to also include a . Includes(:user_purchase_types).
This will eager load the association and avoid rails loading each UserPurchaseType as you iterate through.
Did help thanks, have clarified my thoughts solution below – sopwithpup Sep 28 at 11:40.
Yes you should be able to be able to access typename, but by using @purchase. User_type.typename. And not purchase.
User_type.typename. And would be better if you could show user models too. And is current_user defined?
Also you can try by finding out the usertype first and then access it: @user_type = UserType. Find(@purchase. User_type_id) @user_type.
Typename You should always try the relationships first on console and see if your getting it rgt Your relationships are all messed up. You have a one to many relationships between purchases and user purchase type. And therefore you can not use @purchase.
User_purchase_type. Typename You have to use @purchase. User_purchase_types.
Each do |i| i. Typename end.
This wasn't it sadly – sopwithpup Sep 28 at 11:39.
Simple I think, use belongs_to, they already have the right id fields, should just work. I have tried a million variations of belongs_to, has_many , has_many through etc etc but cannot get the right relationship and so show the typename rather than the id. There are the right foreign_key id fields in the tables so this should work.
When listing the purchases in the purchase controller I use @purchase = current_user.purchases. When looping this to display in the view I think I should be able to use purchase.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.