@blog = Blog.create(name:'My First Blog')
@post = @blog.posts.create(name: 'My first post in My First Blog')
# post is now created and saved
@blog = Blog.find_by_name: 'My First Blog'
@post = @blog.posts.create(name: 'My second post in My First Blog')
# post is now created and saved
@blog = Blog.first
@post = @blog.posts.build(name: 'My third post in my My First Blog')
# post is being built but has not yet been saved
@post.save!
# post is now saved
Probably the easiest thing you can do is understand the types of methods
that are available to each object through their association.
Example (from rails console):
@blog = Blog.first
@blog.methods.sort.each do |method|
p method
end
Or, single line it for posts (just writing it different ways):
@blog.posts.methods.sort.map{ |method| p method }
--
Posted via
http://www.ruby-forum.com/.