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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I hate to ask this, but did you do a @groupmember.save ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/18/07, Mike Riley <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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.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). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter wrote:> On 6/18/07, Mike Riley <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---