Hi, guys, I want to create a controller that assocates multiple models(ActiveRecord), how to building ? For example, my controller called posts, it has the models post , catalog and tag. thanks all. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> One controller, multiple models, how to create ?class PostsController < ApplicationController def new p = Post.new c = Catalog.new t = Tag.new end end class Post < ActiveRecord::Base end class Catalog < ActiveRecord::Base end class Tag < ActiveRecored::Base end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Put all of model class in one file of the post model ? 2011/8/3 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> > One controller, multiple models, how to create ? > > class PostsController < ApplicationController > def new > p = Post.new > c = Catalog.new > t = Tag.new > end > end > > class Post < ActiveRecord::Base > end > > class Catalog < ActiveRecord::Base > end > > class Tag < ActiveRecored::Base > end > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
As far as I know, models aren''t associated with a controller. So you could just ''rails generate model ModelName field:type'' three times for the Post, Catalog, and Tag models. Then in some controller, you can write: class PostsController < ApplicationController def new @title = "Some page" @val = 10 @post = Post.new @post.email = "xxx-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" @catalog = Catalog.new @catalog.name = "Pottery Barn" @tag = Tag.new @tag.name = "dishes" end end And then in new.html.erb, you can write: <h1>Posts#new</h1> <div>Post model: <%= @post.email %></div> <div>Catalog model: <%= @catalog.name %></div> <div>Tag model: <%= @tag.name %></div> <div>Val: <%= @val %></div> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.