Class: EltController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- EltController
- Defined in:
- app/controllers/elt_controller.rb
Overview
This is the central component to parlement
An element is just the name for a poll/message/issue
Instance Method Summary collapse
- #choices ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
- #list ⇒ Object
- #listByDate ⇒ Object
- #listByVote ⇒ Object
-
#new ⇒ Object
Used to initialise the elt, its subject mainly.
- #preview ⇒ Object
- #raw_elt ⇒ Object
- #rss ⇒ Object
- #show ⇒ Object
- #vote ⇒ Object
- #vote_rss ⇒ Object
Instance Method Details
#choices ⇒ Object
122 123 124 |
# File 'app/controllers/elt_controller.rb', line 122 def choices @elt = Elt.find params[:id] end |
#create ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/elt_controller.rb', line 74 def create @elt = Elt.new(params[:elt]) @elt.person = @session[:person] if @elt.subject.match(/([<>\/]|href)/) then logger.error "SPAM! '#{@elt.subject}'" logger.error "SPAM! '#{@elt.body}'" flash[:error] = 'Sorry, to fight spam "<" ">" or "href" are forbidden in the subject!' headers["Status"] = "404 Post considered as spam" render :controller => 'elt', :action => 'new', :status => 404 elsif params[:submit] == "preview" or (@elt.publish and @elt.parent.add_child(@elt)) then headers["Status"] = "201 Created" render :partial => '/elt/elt', :status => 201, :locals => { :elt => @elt, :eltTop => false } else flash[:notice] = 'Error' render :controller => 'elt', :action => 'new' end end |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/elt_controller.rb', line 8 def index params[:id] = params[:id].gsub(/.html/, '') show end |
#list ⇒ Object
31 32 33 34 |
# File 'app/controllers/elt_controller.rb', line 31 def list @elt = Elt.find(params[:id]) if @elt == nil render :partial => '/elt/list', :locals => { :elt => @elt } end |
#listByDate ⇒ Object
36 37 38 39 |
# File 'app/controllers/elt_controller.rb', line 36 def listByDate @elt = Elt.find params[:id] unless @elt render :partial => 'listByDate' end |
#listByVote ⇒ Object
41 42 43 44 |
# File 'app/controllers/elt_controller.rb', line 41 def listByVote @elt = Elt.find params[:id] unless @elt render :partial => 'listByVote' end |
#new ⇒ Object
Used to initialise the elt, its subject mainly
59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/elt_controller.rb', line 59 def new @elt = Elt.new @elt.parent = Elt.find(params[:id]) if @elt.parent.subject.include? 'Re: ' @elt.subject = @elt.parent.subject else @elt.subject = 'Re: '+@elt.parent.subject end end |
#preview ⇒ Object
70 71 72 |
# File 'app/controllers/elt_controller.rb', line 70 def preview render :inline => h(format(params[:elt][:body])) end |
#raw_elt ⇒ Object
93 94 95 96 97 |
# File 'app/controllers/elt_controller.rb', line 93 def raw_elt @mail = Elt.find(params[:id]).mail #@elt = TMail::Mail.parse(Elt.find(params[:id]).mail.id) render :inline => "<pre><%= @mail.file %></pre>", :layout => 'top' end |
#rss ⇒ Object
46 47 48 49 50 |
# File 'app/controllers/elt_controller.rb', line 46 def rss params[:id] = params[:id].gsub(/.rss/, '') @headers["Content-Type"] = "text/xml; charset=utf-8" @elt = Elt.find(params[:id]) if @elt == nil end |
#show ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/elt_controller.rb', line 13 def show params[:id] = params[:id].gsub(/.html/, '') @elt = Elt.find(params[:id]) @title = @elt.subject @title += " (parlement)" if !@title.downcase.include? "parlement" if request.env['REQUEST_URI'].match '.dyndns' headers["Status"] = "301 Moved Permanently" redirect_to request.env['REQUEST_URI'].gsub(/.dyndns/, '') end render :layout => 'top' # TODO rescue ActiveRecord::RecordNotFound => e flash[:error] = "Element '#{params[:id]}' does not exist" headers["Status"] = "301 Moved Permanently" redirect_to '/' end |
#vote ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/elt_controller.rb', line 99 def vote @elt = Elt.find params[:id] vote = @elt.children.build vote.person = session[:person] vote.subject = @elt.subject vote.subject = 'Re: '+vote.subject if vote.subject and !vote.subject.include? 'Re: ' vote.body = params[:choice][:value] choice = Choice.find_by_elt_id_and_person_id @elt.id, (session[:person] ? session[:person].id : nil) if choice and choice.value == vote.body.to_i then logger.info "#{(session[:person] ? session[:person].name : 'null')} voting 0" vote.body = "0" else logger.info "#{(session[:person] ? session[:person].name : 'null')} voting #{params[:choice][:value]}" end vote.publish @elt.add_child vote render :partial => '/elt/choice', :locals => { :elt => @elt } end |
#vote_rss ⇒ Object
52 53 54 55 56 |
# File 'app/controllers/elt_controller.rb', line 52 def vote_rss params[:id] = params[:id].gsub(/.rss/, '') @headers["Content-Type"] = "text/xml; charset=utf-8" @elt = Elt.find(params[:id]) if @elt == nil end |