Forum: Ruby on Rails callbacks

18234c3c6b04ac08d8afb1eeb2e20269?d=identicon&s=25 Avi (Guest)
on 2012-12-17 15:16
(Received via mailing list)
Hello All,

I have two tables:
user has_many room
room belongs_to user

When a new user is created, I want to save the room through some default
values at the same time.
How to do this by using callbacks?

after_save or after_create ?
& I want to use blocks with callbacks.

Any suggestions??


Thanks,
Avi
19fad8b2f5f9948322c3fe0441265298?d=identicon&s=25 Jim ruther Nill (jimboker)
on 2012-12-18 02:03
(Received via mailing list)
On Mon, Dec 17, 2012 at 10:15 PM, Avi <aavinash.behera@gmail.com> wrote:

> Hello All,
>
> I have two tables:
> user has_many room
> room belongs_to user
>
> When a new user is created, I want to save the room through some default
> values at the same time.
> How to do this by using callbacks?
>

> after_save or after_create ?
> & I want to use blocks with callbacks.
>

I'm assuming that a room is unique to a user and you want to create a
room
everytime a user is created
so you need to use the after_create callback.  as for using the syntax
to
use blocks in a callback, you can
look at http://api.rubyonrails.org/classes/ActiveRecord/Ca...


> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-....
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



--
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.