ruby on rails 3 - Create new record gets NameError: undefined local variable or method 'through' -


i'm new rails , following railscast #258 implement jquery tokeninput, , reason in trying create new record i'm getting error:

nameerror: undefined local variable or method `through' #<class:0x101667ef0>     /library/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/base.rb:1008:in `method_missing'     /users/travis/desktop/yourturn/app/models/tag.rb:4     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:454:in `load'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:454:in `load_file'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in `new_constants_in'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:453:in `load_file'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:340:in `require_or_load'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:491:in `load_missing_constant'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:183:in `const_missing'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:181:in `each'     /library/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:181:in `const_missing' 

my tags controller:

class tagscontroller < applicationcontroller  def index     @tags = tag.where("name ?", "%#{params[:q]}%")     respond_to |format|       format.html       format.json { render :json => @tags.map(&:attributes) }     end   end    def show     @tag = tag.find(params[:id])   end    def new     @tag = tag.new   end    def create     @tag = tag.new(params[:tagging])     if @tag.save       redirect_to @tag, :notice => "successfully created tag."     else       render :action => 'new'     end   end 

tags method:

class tag < activerecord::base   attr_accessible :name   has_many :taggings   has_many :questions, through => :taggings end 

taggings method:

class tagging < activerecord::base   attr_accessible :question_id, :tag_id   belongs_to :question   belongs_to :tag end 

method :through:

  has_many :taggings   has_many :tags, :through => :taggings   attr_reader :tag_tokens 

if i'm in terminal , create tag = tagging.new appropriate entries not tag name have in db migrate create_tags. can me figure out issue is? if need provide other code i'm happy to.

you're missing colon, this:

class tag < activerecord::base   attr_accessible :name   has_many :taggings   has_many :questions, through => :taggings end 

should this:

class tag < activerecord::base   attr_accessible :name   has_many :taggings   has_many :questions, :through => :taggings end 

note through changed :through. through variable :through symbol , that's want building hashes.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -