# Insert records into MySQL

**URL:** <https://www.ruby-forum.com/t/insert-records-into-mysql/107196>\
**Category:** Rails\
**Created:** [June 19, 2007, 2:01am UTC](https://www.ruby-forum.com/t/insert-records-into-mysql/107196 "2007-06-19T02:01:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![randall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@randall](https://www.ruby-forum.com/u/randall)\
**Post date:** [June 19, 2007, 2:01am UTC](https://www.ruby-forum.com/t/insert-records-into-mysql/107196/1 "2007-06-19T02:01:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![randall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@randall](https://www.ruby-forum.com/u/randall)\
**Post date:** [June 19, 2007, 11:23am UTC](https://www.ruby-forum.com/t/insert-records-into-mysql/107196/2 "2007-06-19T11:23:35Z")

</div>

I hate to ask this, but did you do a

@groupmember.save

?

---

<div class="post-metadata">

**Author:** ![randall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@randall](https://www.ruby-forum.com/u/randall)\
**Post date:** [June 19, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/insert-records-into-mysql/107196/3 "2007-06-19T15:42:51Z")

</div>

On 6/18/07, Mike R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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).

---

<div class="post-metadata">

**Author:** ![randall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@randall](https://www.ruby-forum.com/u/randall)\
**Post date:** [June 20, 2007, 1:20am UTC](https://www.ruby-forum.com/t/insert-records-into-mysql/107196/4 "2007-06-20T01:20:18Z")

</div>

Bob S. wrote:

> On 6/18/07, Mike R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
