Re: Rails, insert into 3 tables from 1 controller

Javix
Mon, 04 Apr 2011 08:05:07 -0000

Without knowing how your models(Question, Token, Email) are linked by
relations, it''s difficult to advice you. Could you please post it?
Thks

On Apr 4, 9:56 am, HelloRails
<vitalizakhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> Hi.
>
> I have 3 tables: questions, tokens, email.
> When I paste question, some token (rand(9999) for example) inserting,
> too. Its great. But i need paste tokens as much as I have emails in my
> the database called ''Email'' (i have about ~10).
>
> I think i should use each.do for email, but how, following code doesnt
> work
>
> #controller
>
>   def create
>     @w = Digest::SHA1.hexdigest(rand(99999999).to_s)
>
>     @question = Question.new(params[:question])
>
>     if success = @question.save
>            emails = Email.find(:all)             #this pasrt
>            emails.each do |e|                    #doesnt work
>                    Token.create(:token=>@w,:is_active=>"1")
>                end                                    # :(
>            end
>     end
>
>     render :json => @question.to_ext_json(:success => success)
>   end
>
> How can i fix this?

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.