On Wed, Dec 9, 2009 at 5:46 PM, RubyonRails_newbie < [email protected]> wrote:
> > > On 9 Dec, 20:39, RubyonRails_newbie <[email protected]> > wrote: > > On 9 Dec, 16:43, Colin Law <[email protected]> wrote: > > > > > > > > > > > > > 2009/12/9 RubyonRails_newbie <[email protected]>: > > > > > > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

