Insert records into MySQL

Hello all,

 I am struggling with a part of code and not sure where to start my

research. I have created code that will insert a record into MySQL. It
uses the usual standard code created by scaffold:

def create
@group = Group.new(params[:id])
if @group.save
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

What I’d like to do is this: after the @group.save insert another record
into a different table. I would pull the parameters from the form that
was just created. I tried doing this:

@groupmember = Groupmembers.new(:login=> params[:login], :title=>
params[:title])

and it doesn’t work (no error is thrown on my development machine and
checking MySQL there is no record inserted). Thanks for any help or any
resources that may assist me.

Mike

I hate to ask this, but did you do a

@groupmember.save

?

On 6/18/07, Mike R. [email protected] wrote:

resources that may assist me.
new() creates a new object in memory, but doesn’t save it. You can
either use Groupmembers.create(), which does save the row, or
Groupmembers.new() followed by @groupmember.save (or save! if you want
an exception raised on error).

Bob S. wrote:

On 6/18/07, Mike R. [email protected] wrote:

resources that may assist me.
new() creates a new object in memory, but doesn’t save it. You can
either use Groupmembers.create(), which does save the row, or
Groupmembers.new() followed by @groupmember.save (or save! if you want
an exception raised on error).

Isabelle/Bob,

 Thanks for the info.  I actually didn't have a @groupmember.save, 

which I added. However, the other problem I had was the parameters I
was sending. I was using:

:login=> params[:login], :title=> params[:title]

As soon as I used this:

@group.login, @group.title

It was saving the values to the db.

thanks for the info. I appreciate the replies.
Mike

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs