Guest User

Untitled

a guest
Feb 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. ## Migration
  2.  
  3. class CreateArticles < ActiveRecord::Migration
  4. def self.up
  5. create_table :articles do |t|
  6. t.column :subject, :string
  7. t.column :article, :text
  8. t.column :author_id, :integer
  9. t.column :publish_date, :datetime
  10. end
  11. end
  12.  
  13. def self.down
  14. drop_table :articles
  15. end
  16. end
  17.  
  18. ## Article
  19.  
  20. class Article < ActiveRecord::Base
  21.  
  22. belongs_to :author, :class_name => 'Person'
  23. validates_presence_of :author, :article, :subject
  24.  
  25. def marked_down
  26. if @marked_down.nil?
  27. bc = BlueCloth.new(@article)
  28. @marked_down = bc.to_html
  29. else
  30. @marked_down
  31. end
  32. end
  33.  
  34. def get_part(n)
  35. if @message.length > n
  36. i = n+1
  37. while(i > n / 2 && !whitespace?(@article[i,i]))
  38. i-=1
  39. end
  40. return @article[0...i]
  41. else
  42. return @article
  43. end
  44. end
  45. end
  46.  
  47. ## Error should be in here
  48.  
  49. class WriterModule < SecureModule
  50. def initialize
  51. if($cgi['message'].length > 0 && $cgi['subject'].length > 0)
  52. @posted = true
  53. a = Article.new :author => 1, :subject => $cgi['subject'], :article => $cgi['message'], :publish_date => Time.now
  54. # begin
  55. if !a.save
  56. @new_id = a.id
  57. @error = false
  58. else
  59. @error = true
  60. end
  61. # rescue
  62. # puts "<br>error: #{$!}<br>"
  63. # @error = true
  64. # end
  65. else
  66. @posted = false
  67. @error = false
  68. end
  69. end
  70. end
Add Comment
Please, Sign In to add comment