Re: Shouldn''t this insert in table?

Colin Law
Thu, 03 Sep 2009 13:11:36 -0000

2009/9/3 RVince
<rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>:
>
> Guys, Ok here is the code (I changed the class  names and simplified
> in what I sent earlier -- here is the exact code)
> class ChannelsController < ApplicationController
> ..
>  def cxl
>    boxchangedata
>    offToServer
params[''id''].to_i,current_associate.username, " ",
> "Cxl",params[''channelnotes'']
>        puts params[''cxlidx'']
>        if params[''cxlidx''] == "0"
>                Channelnote cnote = Channelnote.new

As Fred pointed out this is not C++, it should be
cnote = Channelnote.new
I kept doing that at first also.

>                cnote.note = params[''channelnotes'']
>                cnote.channel_id = @channel.id
>                cnote.associate_id = current_associate.id

The usual way to do this sort of thing is using the ActiveRecord
relationships, then Rails does all this messy stuff for you.  You
should only very rarely have to mess about with id values.  See the
rails guide on ActiveRecord relationships.

Colin

>                g=cnote.save
>                puts "***"+g.to_s
>        end
>    render :partial => ''channelnotesfield'' # to repop
the box
>  end
> ...
> end
>
> (Channelnote is MyB in the previous). Here is the (exact) error I am
> getting from the log:
>
> NoMethodError (undefined method `Channelnote'' for
#<ChannelsController:
> 0x671df1c>):
>  app/controllers/channels_controller.rb:170:in `cxl''
>
> Thanks for looking at this for me guys -- I''m just confused about
why
> this won''t write a Channelnote record here. -Rvince
> >
>