If I don't have any validations, then it must be that one of the
parameters I am trying to set in the model doesn't comport with what
the database is looking for I assume? Thanks, RVince
Ah, right..it really IS so much easier. Sorry for the dumb Q's here
guys, been stuck in silly Javaland with the day job, and not thinking
the RubyRails-sense properly here. -Rvince
If I don't have any validations, then it must be that one of the
parameters I am trying to set in the model doesn't comport with what
the database is looking for I assume? Thanks, RVince
NoMethodError (undefined method `MyB' for #<MyAController:0x664f93c>):
app/controllers/mya_controller.rb:174:in `cxl'
You could have said that first time round.
Your code reads
MyB myB = MyB.new
I assume you're more familiar with a language where you have to type
and declare variables and this is what you're doing. ruby doesn't do
that though (and probably parses it as MyB(myB = MyB.new)
NoMethodError (undefined method `MyB' for #<MyAController:0x664f93c>):
app/controllers/mya_controller.rb:174:in `cxl'
If you look at the error carefully you will see that it is expecting
MyB to be a method of MyAcController for some reason. Have a look at
the code around line 174 and work out what MyB is supposed to be at
that point. If you cannot see the problem show us the code around the
failure. I notice that it is MyAController, I would expect that to be
MyAsController but that may not be related to this problem.
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
cnote.note = params['channelnotes']
cnote.channel_id = @channel.id
cnote.associate_id = current_associate.id
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
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.
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.
Thanks so much guys! Damn...I'm getting up at 5 am to work on Rails
and learn it and do a project in it, but I'm then 9 hours at the ole
day job (working on the ole railroad...) writing Java hell.
THere's a Federal Building here in town, populated with a bunch of
guys in their 60s with thinning hair and ponytails, writing cobol. If
I just stick with Java I will become one of them! Which is why I am
forcing myself to become rails-proficient (because as I say, Struts if
for guys who don't know Rails under JRuby.)