Hi there, I''ve decided that instead of deleting all posts on a user''s profile, there is now an active_post column in the posts table. Basically, a user has only 1 active post at a time, and the database is either a value of 0 (inactive) or 1(active) I have a problem though. When i add a post, I see that the active column is set to 1. When I add a 2nd post, the most recent is set to active_post = 1 and the initial post is set to 0. (this is as i expect). However - if I delete a post using the link on the page, the database value sets to 0 (also what I want and expect) But - the last post is still displayed on the page. Below is the code on the posts controller, that hopefully explains what I''m doing: Basically - does anyone know how to hide this post? (as it stands the posts for this user are inactive, so should not be visible to them) I think it''s to do with the :conditions. def index #@posts = Post.find_by_user_id( session[:user_id], :order => "created_at DESC") Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post", :order => "created_at desc") @posts = fetchFirstPostForSessionUser() respond_to do |format| format.html end end def create markAsInactive( fetchFirstPostForSessionUser ); @post = Post.create(:message => params[:message], :user_id => session[:user_id]) respond_to do |format| if @post.save format.html { redirect_to :controller => "profile"} flash[:notice] = "Message saved." format.js else flash[:notice] = "Message failed to save." format.html { redirect_to :controller => "profile" } end end end def delete #@post markAsInactive( Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post = 1", :order => "created_at desc")) respond_to do |format| format.html { redirect_to :controller => "user"} #format.xml { head :ok } end end private def markAsInactive( post ) @post = post if not @post.nil? @post.active_post = 0; @post.save end end def fetchFirstPostForSessionUser # TODO Fixme - only fetch active posts Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post = 1", :order => "created_at desc") #Post.find(:all, :conditions => :active_post = ''1'', :order => "created_at DESC") end Many Thanks -- 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.
2009/12/8 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> Hi there, > > I''ve decided that instead of deleting all posts on a user''s profile, > there is now an active_post column in the posts table. > > Basically, a user has only 1 active post at a time, and the database > is either a value of 0 (inactive) or 1(active) > > I have a problem though. When i add a post, I see that the active > column is set to 1. > When I add a 2nd post, the most recent is set to active_post = 1 and > the initial post is set to 0. (this is as i expect). > > However - if I delete a post using the link on the page, the database > value sets to 0 (also what I want and expect) > > But - the last post is still displayed on the page. > > Below is the code on the posts controller, that hopefully explains > what I''m doing: > > Basically - does anyone know how to hide this post? (as it stands the > posts for this user are inactive, so should not be visible to them) > > I think it''s to do with the :conditions. > > def index > #@posts = Post.find_by_user_id( session[:user_id], :order => > "created_at DESC") > Post.find_by_user_id( session[:user_id], 1, :limit => > 1, :conditions => "active_post", :order => "created_at desc")Can you explain what :conditions => "active_post" is supposed to do? Possibly you should be comparing the value of active_post with some value? Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Colin, :conditions active_post is meant to only display posts that are active. If a user deletes a post (they think it''s deleted, but infact it is archived and just set as inactive) as I may want to do something with it at a later date on the site. I looked on the rails api site, I was therefore kinda hoping that : Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post = 1", :order => "created_at desc") would only return posts where the active flag is set to 1. What i''ve done is maybe wrong, but i hope that explanation makes sense....? On 8 Dec, 20:50, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > > > > Hi there, > > > I''ve decided that instead of deleting all posts on a user''s profile, > > there is now an active_post column in the posts table. > > > Basically, a user has only 1 active post at a time, and the database > > is either a value of 0 (inactive) or 1(active) > > > I have a problem though. When i add a post, I see that the active > > column is set to 1. > > When I add a 2nd post, the most recent is set to active_post = 1 and > > the initial post is set to 0. (this is as i expect). > > > However - if I delete a post using the link on the page, the database > > value sets to 0 (also what I want and expect) > > > But - the last post is still displayed on the page. > > > Below is the code on the posts controller, that hopefully explains > > what I''m doing: > > > Basically - does anyone know how to hide this post? (as it stands the > > posts for this user are inactive, so should not be visible to them) > > > I think it''s to do with the :conditions. > > > def index > > #@posts = Post.find_by_user_id( session[:user_id], :order => > > "created_at DESC") > > Post.find_by_user_id( session[:user_id], 1, :limit => > > 1, :conditions => "active_post", :order => "created_at desc") > > Can you explain what :conditions => "active_post" is supposed to do? > Possibly you should be comparing the value of active_post with some > value? > > Colin-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/8 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> Hi Colin, > > :conditions active_post is meant to only display posts that are > active. > > If a user deletes a post (they think it''s deleted, but infact it is > archived and just set as inactive) as I may want to do something with > it at a later date on the site. > > I looked on the rails api site, I was therefore kinda hoping that : > > Post.find_by_user_id( session[:user_id], 1, :limit => > 1, :conditions => "active_post = 1", :order => "created_at desc") > would only return posts where the active flag is set to 1.I would kinda hope that would happen too. What did happen? Is active_post an integer type column or a string? If it is a string then "active_post = ''1''" might be better as integer 1 is not the same as string ''1'' Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
active_post is set as ''tinyint''. What is currently happening is that I hit ''delete''. The active_post column is set to 0, but the post is still visible on the front end. In short - I only want the active post to be visible to the user. If the delete it, it is archived, and no posts visible, until they add a new one - so a user should only ever have 1 active post. Hope this makes sense? Is there a way I can do this? On 8 Dec, 21:08, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > Hi Colin, > > > :conditions active_post is meant to only display posts that are > > active. > > > If a user deletes a post (they think it''s deleted, but infact it is > > archived and just set as inactive) as I may want to do something with > > it at a later date on the site. > > > I looked on the rails api site, I was therefore kinda hoping that : > > > Post.find_by_user_id( session[:user_id], 1, :limit => > > 1, :conditions => "active_post = 1", :order => "created_at desc") > > would only return posts where the active flag is set to 1. > > I would kinda hope that would happen too. What did happen? > > Is active_post an integer type column or a string? If it is a string > then "active_post = ''1''" might be better as integer 1 is not the same > as string ''1'' > > Colin-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/8 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: It is best not to top post, it is easier to follow the thread if things are kept in order, I have reordered.> On 8 Dec, 21:08, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: >>...>> > I looked on the rails api site, I was therefore kinda hoping that : >> >> > Post.find_by_user_id( session[:user_id], 1, :limit => >> > 1, :conditions => "active_post = 1", :order => "created_at desc") >> > would only return posts where the active flag is set to 1. >> >> I would kinda hope that would happen too. What did happen? >> >> Is active_post an integer type column or a string? If it is a string >> then "active_post = ''1''" might be better as integer 1 is not the same >> as string ''1''> active_post is set as ''tinyint''. > > What is currently happening is that I hit ''delete''....What I meant was what does the the query Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post = 1", :order => "created_at desc") return? If this returns a post with active_post not 1 then there is something strange going on. Run it in a console window and see what it returns. Also if you have not done so already work through the rails guide on debugging. This will show you how using ruby-debug you can break in (after that find for example) and see what it has returned. I have just looked at your code again and realised that I was looking at the line before your call to fetchFirstPostForSessionUser, which is not commented out but of course you are ignoring the return value. I see that in fetchFirst.. you are using the condition with = 1 so it should be ok. As I said try debugging and see what it is returning. Also you can look in development.log and see exactly the query being executed. Colin -- 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.
Or you could also change your approach and get only the most recent post, to fulfill that. With a updated_at key, when deleting you could set that to the epoc time or make it null. Don''t know If I really understood your problem. On Tue, Dec 8, 2009 at 6:15 PM, RubyonRails_newbie < craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> active_post is set as ''tinyint''. > > What is currently happening is that I hit ''delete''. > > The active_post column is set to 0, but the post is still visible on > the front end. > > In short - I only want the active post to be visible to the user. If > the delete it, it is archived, and no posts visible, until they add a > new one - so a user should only ever have 1 active post. > > Hope this makes sense? Is there a way I can do this? > > On 8 Dec, 21:08, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > > Hi Colin, > > > > > :conditions active_post is meant to only display posts that are > > > active. > > > > > If a user deletes a post (they think it''s deleted, but infact it is > > > archived and just set as inactive) as I may want to do something with > > > it at a later date on the site. > > > > > I looked on the rails api site, I was therefore kinda hoping that : > > > > > Post.find_by_user_id( session[:user_id], 1, :limit => > > > 1, :conditions => "active_post = 1", :order => "created_at desc") > > > would only return posts where the active flag is set to 1. > > > > I would kinda hope that would happen too. What did happen? > > > > Is active_post an integer type column or a string? If it is a string > > then "active_post = ''1''" might be better as integer 1 is not the same > > as string ''1'' > > > > Colin > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
I''ll have a look around and see whats going on... Many Thanks On 8 Dec, 21:29, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > It is best not to top post, it is easier to follow the thread if > things are kept in order, I have reordered. > > > > > > > > > On 8 Dec, 21:08, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > ... > >> > I looked on the rails api site, I was therefore kinda hoping that : > > >> > Post.find_by_user_id( session[:user_id], 1, :limit => > >> > 1, :conditions => "active_post = 1", :order => "created_at desc") > >> > would only return posts where the active flag is set to 1. > > >> I would kinda hope that would happen too. What did happen? > > >> Is active_post an integer type column or a string? If it is a string > >> then "active_post = ''1''" might be better as integer 1 is not the same > >> as string ''1'' > > active_post is set as ''tinyint''. > > > What is currently happening is that I hit ''delete''.... > > What I meant was what does the the query > Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions > => "active_post = 1", :order => "created_at desc") > return? > > If this returns a post with active_post not 1 then there is something > strange going on. Run it in a console window and see what it returns. > Also if you have not done so already work through the rails guide on > debugging. This will show you how using ruby-debug you can break in > (after that find for example) and see what it has returned. > > I have just looked at your code again and realised that I was looking > at the line before your call to fetchFirstPostForSessionUser, which is > not commented out but of course you are ignoring the return value. I > see that in fetchFirst.. you are using the condition with = 1 so it > should be ok. As I said try debugging and see what it is returning. > Also you can look in development.log and see exactly the query being > executed. > > Colin-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin, Before I debug.... I have had an idea: What about the view? If I can write a decent if statement to only return active_posts that = 1 I should be good to go. I did try this today, but it still showed the inactive post when I set it to 0.. Here''s what I wrote - There''s maybe a better (correct way) to do it... <% if @posts.active_post = 1 %> <% render :partial => posts %> <% end %> <% if @posts.active_post != 1 %> There are no posts! <% end %> Sadly this didn’t work, but I wondered if anyone knew why? I can delete a post, setting the 1 value to a 0, but the post still remains in the view… Hmm. On 8 Dec, 21:29, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > It is best not to top post, it is easier to follow the thread if > things are kept in order, I have reordered. > > > > > > > > > On 8 Dec, 21:08, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> 2009/12/8 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > ... > >> > I looked on the rails api site, I was therefore kinda hoping that : > > >> > Post.find_by_user_id( session[:user_id], 1, :limit => > >> > 1, :conditions => "active_post = 1", :order => "created_at desc") > >> > would only return posts where the active flag is set to 1. > > >> I would kinda hope that would happen too. What did happen? > > >> Is active_post an integer type column or a string? If it is a string > >> then "active_post = ''1''" might be better as integer 1 is not the same > >> as string ''1'' > > active_post is set as ''tinyint''. > > > What is currently happening is that I hit ''delete''.... > > What I meant was what does the the query > Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions > => "active_post = 1", :order => "created_at desc") > return? > > If this returns a post with active_post not 1 then there is something > strange going on. Run it in a console window and see what it returns. > Also if you have not done so already work through the rails guide on > debugging. This will show you how using ruby-debug you can break in > (after that find for example) and see what it has returned. > > I have just looked at your code again and realised that I was looking > at the line before your call to fetchFirstPostForSessionUser, which is > not commented out but of course you are ignoring the return value. I > see that in fetchFirst.. you are using the condition with = 1 so it > should be ok. As I said try debugging and see what it is returning. > Also you can look in development.log and see exactly the query being > executed. > > Colin- Hide quoted text - > > - Show quoted text --- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/9 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> Colin, > > Before I debug.... I have had an idea: > > What about the view? > > If I can write a decent if statement to only return active_posts that > = 1 I should be good to go. I did try this today, but it still showed > the inactive post when I set it to 0.. > > Here''s what I wrote - There''s maybe a better (correct way) to do it... > > <% if @posts.active_post = 1 %>That should be == 1> > <% render :partial => posts %> > > > > <% end %> > > <% if @posts.active_post != 1 %>You can use <% else %> rather then end and another if> > There are no posts! > > <% end %> > > > > Sadly this didn’t work, but I wondered if anyone knew why? I can > delete a post, setting the 1 value to a 0, but the post still remains > in the view…If still not working put in your view some debug: <p>posts active_post value is <%= @posts.active_post %></p> But you would be better off debugging the controller first to check that the query is working correctly. Did you look in development.log to see exactly what query is being run? Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
cool - i''ll give this a go. I hope it''s as simple as == instead of =. Dev log showed my query as a select statement from posts, not specifically looking at the active_post. will try a bit more.... :-) cheers On 9 Dec, 14:05, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > Colin, > > > Before I debug.... I have had an idea: > > > What about the view? > > > If I can write a decent if statement to only return active_posts that > > = 1 I should be good to go. I did try this today, but it still showed > > the inactive post when I set it to 0.. > > > Here''s what I wrote - There''s maybe a better (correct way) to do it... > > > <% if @posts.active_post = 1 %> > > That should be == 1 > > > > > <% render :partial => posts %> > > > <% end %> > > > <% if @posts.active_post != 1 %> > > You can use <% else %> rather then end and another if > > > > > There are no posts! > > > <% end %> > > > Sadly this didn’t work, but I wondered if anyone knew why? I can > > delete a post, setting the 1 value to a 0, but the post still remains > > in the view… > > If still not working put in your view some debug: > <p>posts active_post value is <%= @posts.active_post %></p> > > But you would be better off debugging the controller first to check > that the query is working correctly. Did you look in development.log > to see exactly what query is being run? > > Colin-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/9 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> cool - i''ll give this a go. I hope it''s as simple as == instead of =. > > Dev log showed my query as a select statement from posts, not > specifically looking at the active_post.Are you saying that the :conditions => "active_post = 1" is not in the actual query run? If so then that is the problem. Are you sure you are looking at the right bit of code? I think you need to debug the controller. Colin> > will try a bit more.... :-) >> cheers > > On 9 Dec, 14:05, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: >> >> > Colin, >> >> > Before I debug.... I have had an idea: >> >> > What about the view? >> >> > If I can write a decent if statement to only return active_posts that >> > = 1 I should be good to go. I did try this today, but it still showed >> > the inactive post when I set it to 0.. >> >> > Here''s what I wrote - There''s maybe a better (correct way) to do it... >> >> > <% if @posts.active_post = 1 %> >> >> That should be == 1 >> >> >> >> > <% render :partial => posts %> >> >> > <% end %> >> >> > <% if @posts.active_post != 1 %> >> >> You can use <% else %> rather then end and another if >> >> >> >> > There are no posts! >> >> > <% end %> >> >> > Sadly this didn’t work, but I wondered if anyone knew why? I can >> > delete a post, setting the 1 value to a 0, but the post still remains >> > in the view… >> >> If still not working put in your view some debug: >> <p>posts active_post value is <%= @posts.active_post %></p> >> >> But you would be better off debugging the controller first to check >> that the query is working correctly. Did you look in development.log >> to see exactly what query is being run? >> >> Colin > > -- > > 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@googlegroups.com. > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''ll need to take another look at it. I dont think it''s there, Would it look like select * from posts where active_post = 1? I''ll take a closer look later.. Cheers Colin On 9 Dec, 14:23, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > cool - i''ll give this a go. I hope it''s as simple as == instead of =. > > > Dev log showed my query as a select statement from posts, not > > specifically looking at the active_post. > > Are you saying that the :conditions => "active_post = 1" is not in the > actual query run? If so then that is the problem. Are you sure you > are looking at the right bit of code? I think you need to debug the > controller. > > Colin > > > > > > > will try a bit more.... :-) > > > cheers > > > On 9 Dec, 14:05, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > >> > Colin, > > >> > Before I debug.... I have had an idea: > > >> > What about the view? > > >> > If I can write a decent if statement to only return active_posts that > >> > = 1 I should be good to go. I did try this today, but it still showed > >> > the inactive post when I set it to 0.. > > >> > Here''s what I wrote - There''s maybe a better (correct way) to do it... > > >> > <% if @posts.active_post = 1 %> > > >> That should be == 1 > > >> > <% render :partial => posts %> > > >> > <% end %> > > >> > <% if @posts.active_post != 1 %> > > >> You can use <% else %> rather then end and another if > > >> > There are no posts! > > >> > <% end %> > > >> > Sadly this didn’t work, but I wondered if anyone knew why? I can > >> > delete a post, setting the 1 value to a 0, but the post still remains > >> > in the view… > > >> If still not working put in your view some debug: > >> <p>posts active_post value is <%= @posts.active_post %></p> > > >> But you would be better off debugging the controller first to check > >> that the query is working correctly. Did you look in development.log > >> to see exactly what query is being run? > > >> Colin > > > -- > > > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text - > > - Show quoted text --- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Craig, Also keep in mind that you should not put any kind of logic in the view, try to make your controller or a service do that for you. Putting logic in the view will only cause problems in the feature. Try look at ViewModel Design Pattern On Wed, Dec 9, 2009 at 12:53 PM, RubyonRails_newbie < craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I''ll need to take another look at it. I dont think it''s there, > > Would it look like select * from posts where active_post = 1? > > I''ll take a closer look later.. > > Cheers Colin > > On 9 Dec, 14:23, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > > cool - i''ll give this a go. I hope it''s as simple as == instead of =. > > > > > Dev log showed my query as a select statement from posts, not > > > specifically looking at the active_post. > > > > Are you saying that the :conditions => "active_post = 1" is not in the > > actual query run? If so then that is the problem. Are you sure you > > are looking at the right bit of code? I think you need to debug the > > controller. > > > > Colin > > > > > > > > > > > > > will try a bit more.... :-) > > > > > cheers > > > > > On 9 Dec, 14:05, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > >> 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > >> > Colin, > > > > >> > Before I debug.... I have had an idea: > > > > >> > What about the view? > > > > >> > If I can write a decent if statement to only return active_posts > that > > >> > = 1 I should be good to go. I did try this today, but it still > showed > > >> > the inactive post when I set it to 0.. > > > > >> > Here''s what I wrote - There''s maybe a better (correct way) to do > it... > > > > >> > <% if @posts.active_post = 1 %> > > > > >> That should be == 1 > > > > >> > <% render :partial => posts %> > > > > >> > <% end %> > > > > >> > <% if @posts.active_post != 1 %> > > > > >> You can use <% else %> rather then end and another if > > > > >> > There are no posts! > > > > >> > <% end %> > > > > >> > Sadly this didn’t work, but I wondered if anyone knew why? I can > > >> > delete a post, setting the 1 value to a 0, but the post still > remains > > >> > in the view… > > > > >> If still not working put in your view some debug: > > >> <p>posts active_post value is <%= @posts.active_post %></p> > > > > >> But you would be better off debugging the controller first to check > > >> that the query is working correctly. Did you look in development.log > > >> to see exactly what query is being run? > > > > >> Colin > > > > > -- > > > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm > . > > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > > For more options, visit this group athttp:// > groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text - > > > > - Show quoted text - > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/9 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> I''ll need to take another look at it. I dont think it''s there, > > Would it look like select * from posts where active_post = 1?If it is using the code in fetchFirstPostForSessionUser that you posted earlier, ie Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions => "active_post = 1", :order => "created_at desc") Then it should have all of that in it - the user id the conditions, the order and the limit. If your log is getting large you can just delete it and then run the query to make it easier to find the bits of interest. Colin By the way I do wish you would stop top posting, it makes it much harder to follow what you are replying to. -- 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.
On 9 Dec, 16:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > I''ll need to take another look at it. I dont think it''s there, > > > Would it look like select * from posts where active_post = 1? > > If it is using the code in fetchFirstPostForSessionUser that you > posted earlier, ie > Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions > => "active_post = 1", :order => "created_at desc") > > Then it should have all of that in it - the user id the conditions, > the order and the limit. > > If your log is getting large you can just delete it and then run the > query to make it easier to find the bits of interest. > > Colin > > By the way I do wish you would stop top posting, it makes it much > harder to follow what you are replying to.Sorry about that - it this better? From my log file I have this: UPDATE `posts` SET `updated_at` = ''2009-12-09 20:24:55'', `active_post` = 0 WHERE `id` = 176 That looks correct in my opinion, and what I know about SQL. So - I think the problem is with the view. If the query is working correctly, then all i need to do is correctly show a post (if it is active only) So I wrote this: <% if @posts.active_post == 1 %> <%= render :partial => @posts %> <% end %> This doesn''t return a post - even though the database shows 1 active post. (active_post = 1) Debugging - I''m new to rails and find this hard enough to follow. I''ve not learnt anything about debugging so wouldn''t know where to start. I think the issue is the view, but what do you think? CHeers -- 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.
On 9 Dec, 20:39, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 Dec, 16:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > I''ll need to take another look at it. I dont think it''s there, > > > > Would it look like select * from posts where active_post = 1? > > > If it is using the code in fetchFirstPostForSessionUser that you > > posted earlier, ie > > Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions > > => "active_post = 1", :order => "created_at desc") > > > Then it should have all of that in it - the user id the conditions, > > the order and the limit. > > > If your log is getting large you can just delete it and then run the > > query to make it easier to find the bits of interest. > > > Colin > > > By the way I do wish you would stop top posting, it makes it much > > harder to follow what you are replying to. > > Sorry about that - it this better? > > From my log file I have this: > > UPDATE `posts` SET `updated_at` = ''2009-12-09 20:24:55'', `active_post` > = 0 WHERE `id` = 176 > > That looks correct in my opinion, and what I know about SQL. > > So - I think the problem is with the view. > > If the query is working correctly, then all i need to do is correctly > show a post (if it is active only) > > So I wrote this: > <% if @posts.active_post == 1 %> > <%= render :partial => @posts %> > <% end %> > > This doesn''t return a post - even though the database shows 1 active > post. (active_post = 1) > > Debugging - I''m new to rails and find this hard enough to follow. I''ve > not learnt anything about debugging so wouldn''t know where to start. I > think the issue is the view, but what do you think? > > CHeersHi Colin, You''ll be pleased (relieved) to know I seem to have resoled it. It was the view after all! I changed :> <% if @posts.active_post == 1 %> > <%= render :partial => @posts %>TO: <% if @posts.active_post? %> <%= render :partial => @posts %> This now only renders a post when it is active. When I delete the post, the view displays no posts. Voila. :-) Thanks so much for the posts on this. Perseverance prevailed!!! Regards -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Dec 9, 2009 at 5:46 PM, RubyonRails_newbie < craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > > On 9 Dec, 20:39, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > On 9 Dec, 16:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > > > > > > > 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > > > I''ll need to take another look at it. I dont think it''s there, > > > > > > Would it look like select * from posts where active_post = 1? > > > > > If it is using the code in fetchFirstPostForSessionUser that you > > > posted earlier, ie > > > Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions > > > => "active_post = 1", :order => "created_at desc") > > > > > Then it should have all of that in it - the user id the conditions, > > > the order and the limit. > > > > > If your log is getting large you can just delete it and then run the > > > query to make it easier to find the bits of interest. > > > > > Colin > > > > > By the way I do wish you would stop top posting, it makes it much > > > harder to follow what you are replying to. > > > > Sorry about that - it this better? > > > > From my log file I have this: > > > > UPDATE `posts` SET `updated_at` = ''2009-12-09 20:24:55'', `active_post` > > = 0 WHERE `id` = 176 > > > > That looks correct in my opinion, and what I know about SQL. > > > > So - I think the problem is with the view. > > > > If the query is working correctly, then all i need to do is correctly > > show a post (if it is active only) > > > > So I wrote this: > > <% if @posts.active_post == 1 %> > > <%= render :partial => @posts %> > > <% end %> > > > > This doesn''t return a post - even though the database shows 1 active > > post. (active_post = 1) > > > > Debugging - I''m new to rails and find this hard enough to follow. I''ve > > not learnt anything about debugging so wouldn''t know where to start. I > > think the issue is the view, but what do you think? > > > > CHeers > > > Hi Colin, > > You''ll be pleased (relieved) to know I seem to have resoled it. > > It was the view after all! I changed : > > <% if @posts.active_post == 1 %> > > <%= render :partial => @posts %> > > TO: > <% if @posts.active_post? %> > <%= render :partial => @posts %> > > This now only renders a post when it is active. > When I delete the post, the view displays no posts. Voila. :-) > > Thanks so much for the posts on this. Perseverance prevailed!!! > > Regards > > -- >____________ Rodrigo Dellacqua wrotes: Craig, As I mentioned before, you shoudn''t put that kind of behaviour in your views. That''s a bad design and will lead to maintenance problems in the future. What you should do is apply a ViewModel pattern to that, making this model make the needed changes to your objects and them this ViewModel would be passed in to the view. But you shoudn''t really send all posts to the view and filters on there, you should only retrieve what you are going to use, if you keep that way, you are creating a non-scalable app. []''s Rodrigo Dellacqua -- 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.
On 9 Dec, 22:56, Rodrigo Dellacqua <rgoyta...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Dec 9, 2009 at 5:46 PM, RubyonRails_newbie < > > > > > > craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > On 9 Dec, 20:39, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > On 9 Dec, 16:43, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > 2009/12/9 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > > > > I''ll need to take another look at it. I dont think it''s there, > > > > > > Would it look like select * from posts where active_post = 1? > > > > > If it is using the code in fetchFirstPostForSessionUser that you > > > > posted earlier, ie > > > > Post.find_by_user_id( session[:user_id], 1, :limit => 1, :conditions > > > > => "active_post = 1", :order => "created_at desc") > > > > > Then it should have all of that in it - the user id the conditions, > > > > the order and the limit. > > > > > If your log is getting large you can just delete it and then run the > > > > query to make it easier to find the bits of interest. > > > > > Colin > > > > > By the way I do wish you would stop top posting, it makes it much > > > > harder to follow what you are replying to. > > > > Sorry about that - it this better? > > > > From my log file I have this: > > > > UPDATE `posts` SET `updated_at` = ''2009-12-09 20:24:55'', `active_post` > > > = 0 WHERE `id` = 176 > > > > That looks correct in my opinion, and what I know about SQL. > > > > So - I think the problem is with the view. > > > > If the query is working correctly, then all i need to do is correctly > > > show a post (if it is active only) > > > > So I wrote this: > > > <% if @posts.active_post == 1 %> > > > <%= render :partial => @posts %> > > > <% end %> > > > > This doesn''t return a post - even though the database shows 1 active > > > post. (active_post = 1) > > > > Debugging - I''m new to rails and find this hard enough to follow. I''ve > > > not learnt anything about debugging so wouldn''t know where to start. I > > > think the issue is the view, but what do you think? > > > > CHeers > > > Hi Colin, > > > You''ll be pleased (relieved) to know I seem to have resoled it. > > > It was the view after all! I changed : > > > <% if @posts.active_post == 1 %> > > > <%= render :partial => @posts %> > > > TO: > > <% if @posts.active_post? %> > > <%= render :partial => @posts %> > > > This now only renders a post when it is active. > > When I delete the post, the view displays no posts. Voila. :-) > > > Thanks so much for the posts on this. Perseverance prevailed!!! > > > Regards > > > -- > > ____________ > Rodrigo Dellacqua wrotes: > > Craig, > > As I mentioned before, you shoudn''t put that kind of behaviour in your > views. > > That''s a bad design and will lead to maintenance problems in the future. > > What you should do is apply a ViewModel pattern to that, making this model > make the needed changes to your objects and them this ViewModel would be > passed in to the view. > > But you shoudn''t really send all posts to the view and filters on there, you > should only retrieve what you are going to use, if you keep that way, you > are creating a non-scalable app. > > []''s > Rodrigo Dellacqua- Hide quoted text - > > - Show quoted text -Hi All, Although it may be bad design - i''m going to keep it as it is for the first roll out of my app, and make changes once i''ve found my feet with rails. I need help with the following if statement:> > <% if @posts.active_post? %> > > <%= render :partial => @posts %>This works perfectly if a user has a post. However, If i create a new user (they have no posts) When the user page is then loaded, I get an error regarding the active_post. Obviously as the user is new, and has not posted anything, they now get an error. How can i refine the statement to allow the page to render, even in the case of a new user? Cheers -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/10 RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> ... > > Although it may be bad design - i''m going to keep it as it is for the > first roll out of my app, and make changes once i''ve found my feet > with rails. > > I need help with the following if statement: >> > <% if @posts.active_post? %> >> > <%= render :partial => @posts %> >It has been suggested that you work through some of the Rails guides and learn how to use the available debugging aids, which apparently you do not have the inclination to do. It has also been pointed out that the design you are using is probably not the best but you are pressing on anyway. This is not the best attitude for encouraging others to offer assistance. Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 Dec, 15:48, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/10 RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > > ... > > > Although it may be bad design - i''m going to keep it as it is for the > > first roll out of my app, and make changes once i''ve found my feet > > with rails. > > > I need help with the following if statement: > >> > <% if @posts.active_post? %> > >> > <%= render :partial => @posts %> > > It has been suggested that you work through some of the Rails guides > and learn how to use the available debugging aids, which apparently > you do not have the inclination to do. It has also been pointed out > that the design you are using is probably not the best but you are > pressing on anyway. This is not the best attitude for encouraging > others to offer assistance. > > ColinI wasn''t meaning to have a poor attitude. I was just keen/eager to get my first version of the app out, giving me time to focus on improvements. My app is a seasonal one, so hence the reason for ''pressing on''. I do want to learn the debugging, and am still reading endless posts/ books and tutorials along the way. -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.