Hey guys,
I''m having a hard time with some weird behavior in my application.
Every time I logout a particular has_many relationship seems broken.
When I first login, my relationship user.profile.comments works as
expected, but when I logout and login with another user, I get:
NoMethodError in ProfileController#show
undefined method `comments'' for #<Profile:0x46ff26c>
My Models:
class User < ActiveRecord::Base
has_one :profile
end
class Profile < ActiveRecord::Base
has_many :comments
belongs_to :user
end
class Comment < ActiveRecord::Base
belongs_to :profile
end
And here is my login and logout procedure in my controller:
class UserController < ApplicationController
def login
if request.post?
if session[:user] = User.authenticate(params[:user][:login],
params[:user][:password])
flash[:message] = "Login Successful"
redirect_to_stored
else
flash[:warn] = "Login Error"
end
end
end
def logout
session[:user] = nil
flash[:message] = ''Logged out''
redirect_to :action => ''login''
end
end
Any ideas?
Thanks,
Javier Godinez
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Have you tried restarting your server? By the looks of things, it''s not getting that has_many definition in Profile. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan, Well, if I restart the server it works until I logout and login with the same or another user. I was wondering if anyone has seen behavior like this before. I can code around this with something like Comment.find_all_by_profile_id(@user.profile.id) but I want rails to make this relationship transparent. Thanks, Javier On Dec 27, 2007 7:43 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Have you tried restarting your server? By the looks of things, it''s not > getting that has_many definition in Profile. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
How are you calling comments at the moment? On Dec 28, 2007 2:48 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ryan, > > Well, if I restart the server it works until I logout and login with > the same or another user. > I was wondering if anyone has seen behavior like this before. > I can code around this with something like > Comment.find_all_by_profile_id(@user.profile.id) but I want rails to > make this relationship transparent. > > Thanks, > Javier > > On Dec 27, 2007 7:43 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Have you tried restarting your server? By the looks of things, it''s not > > getting that has_many definition in Profile. > > > > > > > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I am calling it like this:
@profile.comments where @profile = @user.profile
here is the subroutine:
def show
if params[:id]
@user = User.find_by_login(params[:id])
else
@user = User.find(current_user.id)
end
@profile = @user.profile
@photos = Photo.find_all_by_profile_id(@user.profile.id,
:conditions => ["removed = 0"])
@photo = Photo.find_by_profile_id(@user.profile.id, :conditions =>
["removed = 0 AND main = 1"])
if @photo.nil?
@photo = Photo.find(1)
end
@spot_pages, @spots = paginate_collection(
@user.spots.find(:all, :order => ''created_at DESC''),
:page => params[:page])
@buddies = User.find_by_sql(
["SELECT u.* FROM buddies_users b, buddies_users c, users u " +
"WHERE b.buddy_id = ? " +
"AND u.id = b.user_id " +
"AND b.user_id = c.buddy_id " +
"AND b.buddy_id = c.user_id", @user])
@comment_pages, @comments paginate_collection(@profile.comments.find(:all,
:order => ''created_at DESC''), :page =>
params[:page])
end
On Dec 27, 2007 8:19 PM, Ryan Bigg
<radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> How are you calling comments at the moment?
>
>
>
> On Dec 28, 2007 2:48 PM, Javier Godinez
<godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > Ryan,
> >
> > Well, if I restart the server it works until I logout and login with
> > the same or another user.
> > I was wondering if anyone has seen behavior like this before.
> > I can code around this with something like
> > Comment.find_all_by_profile_id(@user.profile.id) but I want rails to
> > make this relationship transparent.
> >
> > Thanks,
> > Javier
> >
> >
> > On Dec 27, 2007 7:43 PM, Ryan Bigg
<radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > > Have you tried restarting your server? By the looks of things,
it''s not
> > > getting that has_many definition in Profile.
> > >
> > > >
> > >
> >
> >
> >
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
OK, I think I figured it out, it seems to me that requiring a model (ActiveRecord::Base) in a controller throws many things off in rails. Has anyone experienced this before? Things such as what I describe below don''t seem to work right. What I was doing is something like: require ''user'' at the top of some controller. Thanks for your help... Javier Godinez On Dec 27, 2007 8:25 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am calling it like this: > @profile.comments where @profile = @user.profile > here is the subroutine: > > > def show > if params[:id] > @user = User.find_by_login(params[:id]) > else > @user = User.find(current_user.id) > end > > @profile = @user.profile > @photos = Photo.find_all_by_profile_id(@user.profile.id, > :conditions => ["removed = 0"]) > @photo = Photo.find_by_profile_id(@user.profile.id, :conditions => > ["removed = 0 AND main = 1"]) > if @photo.nil? > @photo = Photo.find(1) > end > > @spot_pages, @spots = paginate_collection( > @user.spots.find(:all, :order => ''created_at DESC''), > :page => params[:page]) > > @buddies = User.find_by_sql( > ["SELECT u.* FROM buddies_users b, buddies_users c, users u " + > "WHERE b.buddy_id = ? " + > "AND u.id = b.user_id " + > "AND b.user_id = c.buddy_id " + > "AND b.buddy_id = c.user_id", @user]) > > @comment_pages, @comments > paginate_collection(@profile.comments.find(:all, > :order => ''created_at DESC''), :page => params[:page]) > end > > > > > > On Dec 27, 2007 8:19 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How are you calling comments at the moment? > > > > > > > > On Dec 28, 2007 2:48 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Ryan, > > > > > > Well, if I restart the server it works until I logout and login with > > > the same or another user. > > > I was wondering if anyone has seen behavior like this before. > > > I can code around this with something like > > > Comment.find_all_by_profile_id(@user.profile.id) but I want rails to > > > make this relationship transparent. > > > > > > Thanks, > > > Javier > > > > > > > > > On Dec 27, 2007 7:43 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Have you tried restarting your server? By the looks of things, it''s not > > > > getting that has_many definition in Profile. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why are you requring a model in a controller? All models are included automatically. On Jan 3, 2008 3:37 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > OK, I think I figured it out, it seems to me that requiring a model > (ActiveRecord::Base) in a controller throws many things off in rails. > Has anyone experienced this before? Things such as what I describe > below don''t seem to work right. What I was doing is something like: > require ''user'' at the top of some controller. > > Thanks for your help... > Javier Godinez > > On Dec 27, 2007 8:25 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am calling it like this: > > @profile.comments where @profile = @user.profile > > here is the subroutine: > > > > > > def show > > if params[:id] > > @user = User.find_by_login(params[:id]) > > else > > @user = User.find(current_user.id) > > end > > > > @profile = @user.profile > > @photos = Photo.find_all_by_profile_id(@user.profile.id, > > :conditions => ["removed = 0"]) > > @photo = Photo.find_by_profile_id(@user.profile.id, :conditions => > > ["removed = 0 AND main = 1"]) > > if @photo.nil? > > @photo = Photo.find(1) > > end > > > > @spot_pages, @spots = paginate_collection( > > @user.spots.find(:all, :order => ''created_at DESC''), > > :page => params[:page]) > > > > @buddies = User.find_by_sql( > > ["SELECT u.* FROM buddies_users b, buddies_users c, users u " + > > "WHERE b.buddy_id = ? " + > > "AND u.id = b.user_id " + > > "AND b.user_id = c.buddy_id " + > > "AND b.buddy_id = c.user_id", @user]) > > > > @comment_pages, @comments > > paginate_collection(@profile.comments.find(:all, > > :order => ''created_at DESC''), :page => params[:page]) > > end > > > > > > > > > > > > On Dec 27, 2007 8:19 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > How are you calling comments at the moment? > > > > > > > > > > > > On Dec 28, 2007 2:48 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Ryan, > > > > > > > > Well, if I restart the server it works until I logout and login with > > > > the same or another user. > > > > I was wondering if anyone has seen behavior like this before. > > > > I can code around this with something like > > > > Comment.find_all_by_profile_id(@user.profile.id) but I want rails to > > > > make this relationship transparent. > > > > > > > > Thanks, > > > > Javier > > > > > > > > > > > > On Dec 27, 2007 7:43 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Have you tried restarting your server? By the looks of things, > it''s not > > > > > getting that has_many definition in Profile. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, I''ve been working on this for a while, learning as I go and I believe that was something I did erroneously. Thanks. On Jan 2, 2008 9:08 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why are you requring a model in a controller? All models are included > automatically. > > > > On Jan 3, 2008 3:37 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > OK, I think I figured it out, it seems to me that requiring a model > > (ActiveRecord::Base) in a controller throws many things off in rails. > > Has anyone experienced this before? Things such as what I describe > > below don''t seem to work right. What I was doing is something like: > > require ''user'' at the top of some controller. > > > > Thanks for your help... > > Javier Godinez > > > > > > > > > > On Dec 27, 2007 8:25 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am calling it like this: > > > @profile.comments where @profile = @user.profile > > > here is the subroutine: > > > > > > > > > def show > > > if params[:id] > > > @user = User.find_by_login(params[:id]) > > > else > > > @user = User.find(current_user.id) > > > end > > > > > > @profile = @user.profile > > > @photos = Photo.find_all_by_profile_id(@user.profile.id , > > > :conditions => ["removed = 0"]) > > > @photo = Photo.find_by_profile_id(@user.profile.id, :conditions => > > > ["removed = 0 AND main = 1"]) > > > if @photo.nil? > > > @photo = Photo.find(1) > > > end > > > > > > @spot_pages, @spots = paginate_collection( > > > @user.spots.find(:all, :order => ''created_at DESC''), > > > :page => params[:page]) > > > > > > @buddies = User.find_by_sql( > > > ["SELECT u.* FROM buddies_users b, buddies_users c, users u " + > > > "WHERE b.buddy_id = ? " + > > > "AND u.id = b.user_id " + > > > "AND b.user_id = c.buddy_id " + > > > "AND b.buddy_id = c.user_id", @user]) > > > > > > @comment_pages, @comments > > > paginate_collection(@profile.comments.find(:all, > > > :order => ''created_at DESC''), :page => params[:page]) > > > end > > > > > > > > > > > > > > > > > > On Dec 27, 2007 8:19 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > How are you calling comments at the moment? > > > > > > > > > > > > > > > > On Dec 28, 2007 2:48 PM, Javier Godinez <godinezj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > Ryan, > > > > > > > > > > Well, if I restart the server it works until I logout and login with > > > > > the same or another user. > > > > > I was wondering if anyone has seen behavior like this before. > > > > > I can code around this with something like > > > > > Comment.find_all_by_profile_id (@user.profile.id) but I want rails > to > > > > > make this relationship transparent. > > > > > > > > > > Thanks, > > > > > Javier > > > > > > > > > > > > > > > On Dec 27, 2007 7:43 PM, Ryan Bigg <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Have you tried restarting your server? By the looks of things, > it''s not > > > > > > getting that has_many definition in Profile. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > Ryan Bigg > http://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---