Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Migration
- class CreateArticles < ActiveRecord::Migration
- def self.up
- create_table :articles do |t|
- t.column :subject, :string
- t.column :article, :text
- t.column :author_id, :integer
- t.column :publish_date, :datetime
- end
- end
- def self.down
- drop_table :articles
- end
- end
- ## Article
- class Article < ActiveRecord::Base
- belongs_to :author, :class_name => 'Person'
- validates_presence_of :author, :article, :subject
- def marked_down
- if @marked_down.nil?
- bc = BlueCloth.new(@article)
- @marked_down = bc.to_html
- else
- @marked_down
- end
- end
- def get_part(n)
- if @message.length > n
- i = n+1
- while(i > n / 2 && !whitespace?(@article[i,i]))
- i-=1
- end
- return @article[0...i]
- else
- return @article
- end
- end
- end
- ## Error should be in here
- class WriterModule < SecureModule
- def initialize
- if($cgi['message'].length > 0 && $cgi['subject'].length > 0)
- @posted = true
- a = Article.new :author => 1, :subject => $cgi['subject'], :article => $cgi['message'], :publish_date => Time.now
- # begin
- if !a.save
- @new_id = a.id
- @error = false
- else
- @error = true
- end
- # rescue
- # puts "<br>error: #{$!}<br>"
- # @error = true
- # end
- else
- @posted = false
- @error = false
- end
- end
- end
Add Comment
Please, Sign In to add comment