Hi, I have three tables, a domain of Sites, a domain of Users, and a junction of Sites_Users with the tables named as such. My RoR application has a model and controller both User and Site. I tried to add a controller and model named Site_User but I can''t reference any functions in the controller, I get an Uninitialized Constant error. I''m very new to RoR, but not to database development, so I''m not sure what I''m doing incorrectly here. Hopefully someone can point me in the right direction. -- Posted via http://www.ruby-forum.com/.
On Fri, Apr 14, 2006 at 05:21:00AM +0200, Joe Cairns wrote:> Hi, I have three tables, a domain of Sites, a domain of Users, and a > junction of Sites_Users with the tables named as such. > > My RoR application has a model and controller both User and Site. I > tried to add a controller and model named Site_User but I can''t > reference any functions in the controller, I get an Uninitialized > Constant error. > > I''m very new to RoR, but not to database development, so I''m not sure > what I''m doing incorrectly here. Hopefully someone can point me in the > right direction. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >I don''t see why you would want a model named Site_User, or a controller. It is not necicarry to have the join table as a model in order for HABTM relationship to work, as long as the Sites_Users table has two fields, site_id and user_id, you can simply put in the user model: has_and_belongs_to_many :sites And in the site model: has_and_belongs_to_many :users -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060414/a48cdfb4/attachment.bin
Christian wrote:> On Fri, Apr 14, 2006 at 05:21:00AM +0200, Joe Cairns wrote: >> right direction. >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > I don''t see why you would want a model named Site_User, or a controller. > It is not necicarry to have the join table as a model in order for HABTM > relationship to work, as long as the Sites_Users table has two fields, > site_id and user_id, you can simply put in the user model: > has_and_belongs_to_many :sites > And in the site model: > has_and_belongs_to_many :usersOk, I didn''t think I needed the model, but added one when things weren''t working. However, I want a function to find if a user is a member of a certain site. So I added a controller with that functionality. This is where I get the Uninitialized Constant problem... when I call: Site_user.ismember? -- Posted via http://www.ruby-forum.com/.
That may be because in ruby, constants are defined with Uppercase characters, wheras variables are defined lowercase. You should look at lowercasing some of your variable names that you don''t want explicitly as constants. On 4/14/06, Joe Cairns <joe.cairns@gmail.com> wrote:> > Christian wrote: > > On Fri, Apr 14, 2006 at 05:21:00AM +0200, Joe Cairns wrote: > >> right direction. > >> > >> -- > >> Posted via http://www.ruby-forum.com/. > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > I don''t see why you would want a model named Site_User, or a controller. > > It is not necicarry to have the join table as a model in order for HABTM > > relationship to work, as long as the Sites_Users table has two fields, > > site_id and user_id, you can simply put in the user model: > > has_and_belongs_to_many :sites > > And in the site model: > > has_and_belongs_to_many :users > > Ok, I didn''t think I needed the model, but added one when things weren''t > working. However, I want a function to find if a user is a member of a > certain site. So I added a controller with that functionality. > > This is where I get the Uninitialized Constant problem... > when I call: Site_user.ismember? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060414/52384481/attachment.html