Subject
Message The Rails new_controller script would've generated something like the following:
require 'abstract_application' require 'forum_helper' class ForumController < AbstractApplicationController include ForumHelper end
require 'abstract_application' require 'forum_helper' require 'post' require 'comment' class ForumController < AbstractApplicationController include ForumHelper scaffold :post scaffold :comment, :suffix => true def show # when showing a Post, i need to retrieve all the comments too # thus @post and @comments is populated here. sqlId = ForumController.quote(@params["id"]) @post = Post.find(@params["id"]); @comments = Comment.find_all "post_id = #{sqlId}" # after populating our variables, we'll call scaffold to render # using the 'show.rhtml' render_scaffold end def list_comment # default action "list_comment" will show all the comments in # the database, doesn't make sense in our app - so redirect to # the list topics screen list end def list # The 'type' column is automagically used by Rails.. when inserting # a comment, it put 'Comment' as its 'type' value # Hence, to get all the topics, we'll get the 'type is null'.. @posts = Post.find_all "type is null order by created_at desc limit 30" render_scaffold end # Java programmers, this is a static / class function # Putting this function here because I still haven't learnt to # use Rails / ActiveRecord for this purpose.. def ForumController.quote(value) case value when String then "'#{value.gsub(/\\/,'\&\&').gsub(/'/, "''")}'" # ' (for ruby-mode) when NilClass then "NULL" when Float, Fixnum, Date then "'#{value.to_s}'" when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'" else "'#{value.to_yaml}'" end end end
Author
Email
Url
Created at 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 January February March April May June July August September October November December 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 — 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59