Ruby on Rails
Friday, August 16, 2013
On Wednesday, 14 August 2013 07:53:20 UTC-4, Павел Добренко wrote:
i have such model:class ToType < ActiveRecord::Baseattr_accessible :Name, :TYP_CCM, :TYP_CCM_TAX, :TYP_CDS_ID, :TYP_CTM, :TYP_CYLINDERS, :TYP_DOORS, :TYP_HP_FROM, :TYP_HP_UPTO, :TYP_ID, :TYP_KV_ABS_DES_ID, :TYP_KV_ASR_DES_ID, :TYP_KV_AXLE_DES_ID, :TYP_KV_BODY_DES_ID, :TYP_KV_BRAKE_SYST_DES_ID, :TYP_KV_BRAKE_TYPE_DES_ID, :TYP_KV_CATALYST_DES_ID, :TYP_KV_DRIVE_DES_ID, :TYP_KV_ENGINE_DES_ID, :TYP_KV_FUEL_DES_ID, :TYP_KV_FUEL_SUPPLY_DES_ID, :TYP_KV_MODEL_DES_ID, :TYP_KV_STEERING_DES_ID, :TYP_KV_STEERING_SIDE_DES_ID, :TYP_KV_TRANS_DES_ID, :TYP_KV_VOLTAGE_DES_ID, :TYP_KW_FROM, :TYP_KW_UPTO, :TYP_LA_CTM, :TYP_LITRES, :TYP_MAX_WEIGHT, :TYP_MMT_CDS_ID, :TYP_MOD_ID, :TYP_PCON_END, :TYP_PCON_START, :TYP_RT_EXISTS, :TYP_SORT, :TYP_TANK, :TYP_VALVES, :is_in_toset_primary_key :TYP_IDbelongs_to :to_model
This is likely the problem - ActiveModel expects an instance of ToType to have a method to_model. The default implementation just returns the object, but the belongs_to here is overriding that and messing things up.
I'd recommend naming the association something else.
--Matt Jones
has_many :to_articles, :foreign_key => "to_type_id", :dependent => :destroyendclass ToArticle < ActiveRecord::Baseattr_accessible :details, :manufacturer, :name, :oem_number, :only_with_vin, :quantity, :to_type_idbelongs_to :to_type, :foreign_key => "TYP_ID"belongs_to :to_engineend(some db is converted from big catalog, so rails conventions are a little bit missed)my show view of to_type is:part of it:%td= link_to "Подробнее", admin_catalog_to_to_article_path(c), :class=>'btn btn-primary' = link_to "Редактирование", edit_admin_catalog_to_to_type_path(c), :class=>'btn btn-warning' = link_to "Удалить", admin_catalog_to_to_type_path(c), :confirm => "!!!Тип #{c.Name} будет удалён!!!! Вы уверены?", :method => :delete, :class => "btn btn-danger" my show action work normally, also controller:class Admin::Catalog::To::ToTypesController < ApplicationController respond_to :htmlbefore_filter :auth_userdef auth_userredirect_to new_admin_session_path unless admin_signed_in?enddef show@mod_id = params[:id]@man = ToType.find(:all, conditions: {:TYP_MOD_ID => @mod_id}, order: "Name ASC")render :layout => 'admin'enddef edit@man = ToType.find(params[:id])render :layout => 'admin'enddef update@man = ToType.find(params[:id])if @man.update_attributes(params[:to_type]) redirect_to admin_catalog_to_to_type_path(@man.TYP_MOD_ID) elserender :layout => 'admin'endenddef new@man = ToType.new@mod_id = params[:mod_id]render :layout => 'admin'enddef create@man = ToType.new(params[:to_type])@mod_id = params[:mod_id]@man.TYP_MOD_ID = @mod_idif @man.saveredirect_to admin_catalog_to_to_type_path(@mod_id) elserender :layout => 'admin'endenddef destroy@man = ToType.find(params[:id])if @man.destroyredirect_to admin_catalog_to_to_type_path(@man.TYP_MOD_ID) elserender :layout => 'admin'endendendand route:namespace :admin donamespace :catalog donamespace :to doresources :to_manufacturers,:to_models,:to_types,:to_articlesendendendform partial:= form_for [:admin, :catalog, :to, @typ] do |f|= f.label :id...when i try edit or create i get:undefined method `model_name' for NilClass:Classi think that something is bad with connection with model: with update and create. In log i see that object is founded in db for edit for example, and in log i can see that @man is not empty, but i still get undefined method `model_name' for NilClass:Class . Why?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f9c7bc2e-3004-4665-a727-37d366536f29%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment