From 0991d7af8eb3928bdee45ca06b4ba9c41871b59b Mon Sep 17 00:00:00 2001 From: Alinson S Xavier Date: Sun, 14 Jul 2013 11:11:18 -0400 Subject: [PATCH] rails 3 fixes --- .hgignore | 4 ++ Gemfile | 13 ++-- Gemfile.lock | 2 + app/controllers/application_controller.rb | 4 +- app/controllers/attachments_controller.rb | 2 +- app/controllers/wiki_controller.rb | 4 +- app/helpers/application_helper.rb | 2 +- app/helpers/wiki_helper.rb | 3 +- app/models/attachment.rb | 4 +- app/models/wiki_page.rb | 2 + app/views/attachments/edit.html.haml | 2 +- app/views/attachments/new.html.haml | 2 +- app/views/courses/edit.html.haml | 2 +- app/views/courses/new.html.haml | 2 +- app/views/events/edit.html.haml | 2 +- app/views/events/new.html.haml | 2 +- app/views/layouts/attachments.html.haml | 8 +-- app/views/layouts/courses.html.haml | 4 +- app/views/layouts/events.html.haml | 6 +- app/views/layouts/log.html.haml | 8 +-- app/views/layouts/news.html.haml | 6 +- app/views/layouts/users.html.haml | 4 +- app/views/layouts/wiki.html.haml | 8 +-- app/views/news/edit.html.haml | 2 +- app/views/news/new.html.haml | 2 +- app/views/user/change_password.html.erb | 2 +- app/views/user/edit.html.erb | 2 +- app/views/user/forgot_password.html.erb | 2 +- app/views/user/login.html.erb | 2 +- app/views/user/show.html.erb | 4 +- app/views/user/signup.html.erb | 2 +- app/views/users/dashboard.html.haml | 4 +- app/views/users/edit.html.haml | 2 +- app/views/users/login.html.haml | 2 +- app/views/users/recover_password.html.haml | 4 +- app/views/users/settings.html.haml | 2 +- app/views/users/signup.html.haml | 2 +- app/views/widgets/shoutbox.html.erb | 2 +- app/views/wiki/edit.html.haml | 2 +- app/views/wiki/new.html.haml | 2 +- app/views/wiki/versions.html.haml | 2 +- config/application.rb | 9 +++ config/environment.rb | 5 ++ config/initializers/nasty_hacks.rb.rails2 | 64 ------------------ lib/authentication.rb | 2 +- lib/nasty_hacks.rb | 75 ++++++++++++++++++++++ 46 files changed, 164 insertions(+), 129 deletions(-) delete mode 100644 config/initializers/nasty_hacks.rb.rails2 create mode 100644 lib/nasty_hacks.rb diff --git a/.hgignore b/.hgignore index a74dc4a..2c773f3 100644 --- a/.hgignore +++ b/.hgignore @@ -6,3 +6,7 @@ public/upload/* *.orig config/database.yml config/application.rb +tmp/cache/* +*.rails2 +*.sqlite3 +*.pid diff --git a/Gemfile b/Gemfile index d4db0c4..67bd75c 100644 --- a/Gemfile +++ b/Gemfile @@ -10,17 +10,18 @@ group :assets do gem 'uglifier', '>= 1.0.3' end -gem 'jquery-rails' +gem 'acts_as_list', '~>0.2' +gem 'acts_as_paranoid', '~>0.4' +gem 'acts_as_versioned', :git => 'https://github.com/jwhitehorn/acts_as_versioned.git' gem 'bluecloth', '1.0.0', :path => './vendor/gems/bluecloth' +gem 'calendar_helper', "~>0.2" +gem 'dynamic_form' gem 'haml', '~>3.1' gem 'hpricot', '~>0.8' gem 'icalendar', '~>1.0' -gem 'will_paginate', "~>3.0" -gem 'calendar_helper', "~>0.2" +gem 'jquery-rails' gem 'shoulda', "~>2.11" -gem 'acts_as_paranoid', '~>0.4' -gem 'acts_as_versioned', :git => 'https://github.com/jwhitehorn/acts_as_versioned.git' -gem 'acts_as_list', '~>0.2' +gem 'will_paginate', "~>3.0" group :development, :production do gem 'brazilian-rails', '3.3.0', :path => './vendor/gems/brazilian-rails/brI18n/' diff --git a/Gemfile.lock b/Gemfile.lock index 1d2ab78..283e2c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,7 @@ GEM execjs coffee-script-source (1.6.3) daemons (1.1.9) + dynamic_form (1.1.4) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) @@ -148,6 +149,7 @@ DEPENDENCIES brazilian-rails (= 3.3.0)! calendar_helper (~> 0.2) coffee-rails (~> 3.2.1) + dynamic_form haml (~> 3.1) hpricot (~> 0.8) icalendar (~> 1.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5f05c66..747f0fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base respond_to do |format| format.html { if logged_in? - render :file => "#{RAILS_ROOT}/public/401.html", :status => 401 + render :file => "#{Rails.root}/public/401.html", :status => 401 else login_by_html end @@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base # Registro nao encontrado elsif (RAILS_ENV == 'production') and exception.is_a?(ActiveRecord::RecordNotFound) respond_to do |format| - format.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 } + format.html { render :file => "#{Rails.root}/public/404.html", :status => 404 } format.xml { head 404 } end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 248f517..36e8c9f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -98,7 +98,7 @@ class AttachmentsController < ApplicationController def download - send_file("#{RAILS_ROOT}/public/upload/#{@course.id}/#{@attachment.id}", + send_file("#{Rails.root}/public/upload/#{@course.id}/#{@attachment.id}", :filename => @attachment.file_name, :type => @attachment.content_type, :disposition => 'inline', diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 6eb8b21..b803a16 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -18,8 +18,8 @@ class WikiController < ApplicationController - verify :params => :text, :only => :preview, :redirect_to => { :action => :show } - verify :params => [:from, :to], :only => :diff, :redirect_to => { :action => :versions } + #verify :params => :text, :only => :preview, :redirect_to => { :action => :show } + #verify :params => [:from, :to], :only => :diff, :redirect_to => { :action => :versions } #after_filter :cache_sweep, :only => [ :create, :update, :destroy, :move_up, # :move_down, :undelete ] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ed0f70c..fe97b34 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -73,7 +73,7 @@ module ApplicationHelper def markup_help return "" end diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index d63f841..3b1543c 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -16,10 +16,11 @@ # along with this program. If not, see . class String + include ActionView::Helpers::SanitizeHelper def format_wiki text = BlueCloth.new(self).to_html text = Hpricot(text, :xhtml_strict => true).to_s - return text.sanitize unless text.blank? + return sanitize text end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ef04f15..a3e5c23 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -62,7 +62,7 @@ class Attachment < ActiveRecord::Base # Salva o arquivo fisicamente no HD def after_save - @file_path = "#{RAILS_ROOT}/public/upload/#{course.id}/#{self.id}" + @file_path = "#{Rails.root}/public/upload/#{course.id}/#{self.id}" FileUtils.mkdir_p(File.dirname(@file_path)) if @tmp_file @@ -75,7 +75,7 @@ class Attachment < ActiveRecord::Base # Deleta o arquivo #def after_destroy - # @file_path = "#{RAILS_ROOT}/public/upload/#{course.id}/#{self.id}" + # @file_path = "#{Rails.root}/public/upload/#{course.id}/#{self.id}" # File.delete(@file_path) if File.exists?(@file_path) #end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index fcc5e6c..3cc2d49 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -21,6 +21,8 @@ require 'tempfile' class WikiPage < ActiveRecord::Base + attr_accessible :title, :front_page, :content, :description + # Plugins acts_as_paranoid acts_as_list :scope => 'course_id = #{course_id}' diff --git a/app/views/attachments/edit.html.haml b/app/views/attachments/edit.html.haml index 9af74b3..b8d22b4 100644 --- a/app/views/attachments/edit.html.haml +++ b/app/views/attachments/edit.html.haml @@ -2,6 +2,6 @@ %h1.title Modificar arquivo %p - - form_for :attachment, @attachment, :url => course_attachment_url, :html => { :method => 'put', :multipart => 'true' } do + = form_for @attachment, :url => course_attachment_url, :html => { :method => 'put', :multipart => 'true' } do = render :partial => 'form' = submit_tag 'Editar', :accesskey => 'e' diff --git a/app/views/attachments/new.html.haml b/app/views/attachments/new.html.haml index f35cace..684ad7a 100644 --- a/app/views/attachments/new.html.haml +++ b/app/views/attachments/new.html.haml @@ -2,6 +2,6 @@ %h1.title Adicionar arquivo %p - - form_for :attachment, @attachment, :url => course_attachments_url, :html => { :method => 'post', :multipart => 'true' } do + = form_for @attachment, :url => course_attachments_url, :html => { :method => 'post', :multipart => 'true' } do = render :partial => 'form' = submit_tag "Criar", :accesskey => 'e' diff --git a/app/views/courses/edit.html.haml b/app/views/courses/edit.html.haml index cfb169a..b1a8b8e 100644 --- a/app/views/courses/edit.html.haml +++ b/app/views/courses/edit.html.haml @@ -2,6 +2,6 @@ %h1.title Editar disciplina %p - - form_tag course_path(@course.id), :method => :put do + = form_tag course_path(@course.id), :method => :put do = render :partial => 'form' = submit_tag 'Editar', :accesskey => 'e' diff --git a/app/views/courses/new.html.haml b/app/views/courses/new.html.haml index d8f9484..d762f91 100644 --- a/app/views/courses/new.html.haml +++ b/app/views/courses/new.html.haml @@ -1,6 +1,6 @@ %h4.title= App.title %h1.title Adicionar disciplina -- form_tag courses_url, :method => :post do += form_tag courses_url, :method => :post do = render :partial => 'form' = submit_tag "Cadastrar", :accesskey => 'e' diff --git a/app/views/events/edit.html.haml b/app/views/events/edit.html.haml index 9e62540..4cfedbe 100644 --- a/app/views/events/edit.html.haml +++ b/app/views/events/edit.html.haml @@ -2,6 +2,6 @@ %h1.title Editar evento %p - - form_tag course_event_url(@course, @event), :method => :put do + = form_tag course_event_url(@course, @event), :method => :put do = render :partial => 'form' = submit_tag 'Editar', :accesskey => 'e' diff --git a/app/views/events/new.html.haml b/app/views/events/new.html.haml index 3d65bfa..0801f46 100644 --- a/app/views/events/new.html.haml +++ b/app/views/events/new.html.haml @@ -2,6 +2,6 @@ %h1.title Adicionar evento %p - - form_tag course_events_url(@course), :method => :post do + = form_tag course_events_url(@course), :method => :post do = render :partial => 'form' = submit_tag "Adicionar", :accesskey => 'e' diff --git a/app/views/layouts/attachments.html.haml b/app/views/layouts/attachments.html.haml index 9c3a86f..2d8a713 100644 --- a/app/views/layouts/attachments.html.haml +++ b/app/views/layouts/attachments.html.haml @@ -1,11 +1,11 @@ - @title = "#{App.title} - #{h(@course.full_name)}" - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›" - = link_to("Disciplinas", courses_url) + "›" - = link_to(h(@course.full_name), course_url(@course)) + "›" + = link_to(App.title, index_url, :accesskey => 'z') + "›" + = link_to("Disciplinas", courses_url) + "›" + = link_to(h(@course.full_name), course_url(@course)) + "›" = link_to("Arquivos", course_attachments_url(@course)) - if @attachment.id - = "›" + link_to(truncate(h(@attachment.file_name)), course_attachment_url) + = "›" + link_to(truncate(h(@attachment.file_name)), course_attachment_url) - @title = @title + " - #{truncate(h(@attachment.file_name))}" - @left_panel = render 'courses/left_panel' diff --git a/app/views/layouts/courses.html.haml b/app/views/layouts/courses.html.haml index 394f865..75996f9 100644 --- a/app/views/layouts/courses.html.haml +++ b/app/views/layouts/courses.html.haml @@ -1,9 +1,9 @@ - @title = "#{App.title}" - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›"; + = link_to(App.title, index_url, :accesskey => 'z') + "›"; = link_to("Disciplinas", courses_url) - if @course and @course.id - = "› " + link_to(h(@course.full_name), course_url) + = "› " + link_to(h(@course.full_name), course_url) - @title = @title + " - #{h(@course.full_name)}" - else - @title = @title + " - Disciplinas" diff --git a/app/views/layouts/events.html.haml b/app/views/layouts/events.html.haml index e44c279..56b1469 100644 --- a/app/views/layouts/events.html.haml +++ b/app/views/layouts/events.html.haml @@ -1,8 +1,8 @@ - @title = "#{App.title} - #{h(@course.full_name)} - Calendário" - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›" - = link_to("Disciplinas", courses_url) + "›" - = link_to(h(@course.full_name), course_url(@course)) + "›" + = link_to(App.title, index_url, :accesskey => 'z') + "›" + = link_to("Disciplinas", courses_url) + "›" + = link_to(h(@course.full_name), course_url(@course)) + "›" = link_to("Calendário", course_events_url) - @left_panel = render 'courses/left_panel' diff --git a/app/views/layouts/log.html.haml b/app/views/layouts/log.html.haml index b10640d..721b3c4 100644 --- a/app/views/layouts/log.html.haml +++ b/app/views/layouts/log.html.haml @@ -1,9 +1,9 @@ - if @course - @title = "#{App.title} - #{h(@course.full_name)} - Mudanças recentes" - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›" - = link_to("Disciplinas", courses_url) + "›" - = link_to(h(@course.full_name), course_url(@course)) + "›" + = link_to(App.title, index_url, :accesskey => 'z') + "›" + = link_to("Disciplinas", courses_url) + "›" + = link_to(h(@course.full_name), course_url(@course)) + "›" = link_to("Mudanças Recentes", course_log_url(@course)) - @left_panel = render 'courses/left_panel' @@ -12,7 +12,7 @@ - else - @title = "#{App.title} - Mudanças recentes" - @location = capture do - = link_to(App.title, index_url) + "›" + = link_to(App.title, index_url) + "›" = link_to("Mudanças recentes", log_url) - @content = yield diff --git a/app/views/layouts/news.html.haml b/app/views/layouts/news.html.haml index 9092ba9..4940318 100644 --- a/app/views/layouts/news.html.haml +++ b/app/views/layouts/news.html.haml @@ -1,8 +1,8 @@ - @title = "#{App.title} - #{h(@course.full_name)} - Notícias" - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›" - = link_to("Disciplinas", courses_url) + "›" - = link_to(h(@course.full_name), course_url(@course)) + "›" + = link_to(App.title, index_url, :accesskey => 'z') + "›" + = link_to("Disciplinas", courses_url) + "›" + = link_to(h(@course.full_name), course_url(@course)) + "›" = link_to("Noticias", course_news_url(@course)) - @left_panel = render 'courses/left_panel' diff --git a/app/views/layouts/users.html.haml b/app/views/layouts/users.html.haml index a96d832..11b6a4e 100644 --- a/app/views/layouts/users.html.haml +++ b/app/views/layouts/users.html.haml @@ -1,9 +1,9 @@ - @title = App.title - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›"; + = link_to(App.title, index_url, :accesskey => 'z') + "›"; = link_to("Usuários", users_path) - if @user and @user.id - = "› " + link_to(h(@user.name), user_url(@user)) + = "› " + link_to(h(@user.name), user_url(@user)) - @title = @title + " - #{h(@user.display_name)}" - @left_panel = render('widgets/menu_navigation') + render('widgets/menu_user') diff --git a/app/views/layouts/wiki.html.haml b/app/views/layouts/wiki.html.haml index 3f7c915..e484e3e 100644 --- a/app/views/layouts/wiki.html.haml +++ b/app/views/layouts/wiki.html.haml @@ -1,11 +1,11 @@ - @title = "#{App.title} - #{h(@course.full_name)}" - @location = capture do - = link_to(App.title, index_url, :accesskey => 'z') + "›" - = link_to("Disciplinas", courses_url) + "›" - = link_to(h(@course.full_name), course_url(@course)) + "›" + = link_to(App.title, index_url, :accesskey => 'z') + "›" + = link_to("Disciplinas", courses_url) + "›" + = link_to(h(@course.full_name), course_url(@course)) + "›" = link_to("Wiki", course_wiki_url(@course)) - if @wiki_page.title? - = "›" + link_to(h(@wiki_page.title), course_wiki_instance_url(@course, @wiki_page)) + = "›" + link_to(h(@wiki_page.title), course_wiki_instance_url(@course, @wiki_page)) - @title = @title + " - #{h(@wiki_page.title)}" - @left_panel = render 'courses/left_panel' diff --git a/app/views/news/edit.html.haml b/app/views/news/edit.html.haml index 0c45b9e..4e104c6 100644 --- a/app/views/news/edit.html.haml +++ b/app/views/news/edit.html.haml @@ -2,6 +2,6 @@ %h1.title Editar noticia %p - - form_tag course_news_instance_url(@course, @news), :method => :put do + = form_tag course_news_instance_url(@course, @news), :method => :put do = render :partial => 'form' = submit_tag 'Editar', :accesskey => 'e' diff --git a/app/views/news/new.html.haml b/app/views/news/new.html.haml index e860011..fbe76e2 100644 --- a/app/views/news/new.html.haml +++ b/app/views/news/new.html.haml @@ -1,6 +1,6 @@ %h4.title= @course.full_name %h1.title Adicionar notícia -- form_tag course_news_url, :method => :post do += form_tag course_news_url, :method => :post do = render :partial => 'form' = submit_tag "Adicionar", :accesskey => 'e' diff --git a/app/views/user/change_password.html.erb b/app/views/user/change_password.html.erb index e2fe8ec..fcb6410 100644 --- a/app/views/user/change_password.html.erb +++ b/app/views/user/change_password.html.erb @@ -4,7 +4,7 @@

<%= error_messages_for 'user' %>
-<% form_tag :action => 'change_password' do %> +<%= form_tag :action => 'change_password' do %>
<%= password_field "user", "password", :size => 20, :value=>"" %>
diff --git a/app/views/user/edit.html.erb b/app/views/user/edit.html.erb index 185b20d..a6c0583 100644 --- a/app/views/user/edit.html.erb +++ b/app/views/user/edit.html.erb @@ -4,7 +4,7 @@

<%= error_messages_for 'user' %>
-<% form_tag :action => 'update', :id => @user do %> +<%= form_tag :action => 'update', :id => @user do %>
<%= text_field "user", "name", :size => 20 %>
diff --git a/app/views/user/forgot_password.html.erb b/app/views/user/forgot_password.html.erb index a7798b4..5db8ce3 100644 --- a/app/views/user/forgot_password.html.erb +++ b/app/views/user/forgot_password.html.erb @@ -4,7 +4,7 @@

<%= error_messages_for 'user' %>
-<% form_tag :action=>'forgot_password' do %> +<%= form_tag :action=>'forgot_password' do %> Email
<%= text_field "user","email" %>

diff --git a/app/views/user/login.html.erb b/app/views/user/login.html.erb index f6f7627..84994f4 100644 --- a/app/views/user/login.html.erb +++ b/app/views/user/login.html.erb @@ -4,7 +4,7 @@

<%= error_messages_for 'user' %>
-<% form_tag :action=> "login" do %> +<%= form_tag :action=> "login" do %>
<%= text_field "user", "login", :size => 20 %>
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index 5b3c850..875df31 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -13,7 +13,7 @@ <% @news_messages.each do |n| %>

<%= n.timestamp.strftime("%d de %B") %>

-

<%= link_to h(n.course.full_name) , course_news_instance_url(n.course, n) %> › +

<%= link_to h(n.course.full_name) , course_news_instance_url(n.course, n) %> › <%= h(n.title) %>

  • <%= event.time.strftime("%H:%M") %>
    - <%= link_to h(event.course.full_name), course_event_url(event.course, event) %> › + <%= link_to h(event.course.full_name), course_event_url(event.course, event) %> › <%= h(event.title) %>
  • Carregando...
  • <% if session[:user] %> - <% form_tag( + <%= form_tag( {:controller => 'message', :action => 'create'}, {:id => 'shoutbox_form' }) do %>
    <%= text_area :message, :body %> diff --git a/app/views/wiki/edit.html.haml b/app/views/wiki/edit.html.haml index e9448e8..811ba89 100644 --- a/app/views/wiki/edit.html.haml +++ b/app/views/wiki/edit.html.haml @@ -4,7 +4,7 @@ %h1.title= "Editar #{h(@wiki_page.title)}" %p - - form_tag course_wiki_instance_url(@course, @wiki_page.id), :method => :put do + = form_tag course_wiki_instance_url(@course, @wiki_page.id), :method => :put do = render :partial => 'form' = submit_tag 'Salvar', :accesskey => 'e' %button#show_preview{:type => "button", :accesskey => 'v'} diff --git a/app/views/wiki/new.html.haml b/app/views/wiki/new.html.haml index 87ad2a3..f2a11cf 100644 --- a/app/views/wiki/new.html.haml +++ b/app/views/wiki/new.html.haml @@ -4,7 +4,7 @@ %h1.title Adicionar página wiki %p - - form_tag course_wiki_url(@course) do + = form_tag course_wiki_url(@course) do = render :partial => 'form' = submit_tag "Criar", :accesskey => 'e' %button#show_preview{:type => "button", :accesskey => 'v'} diff --git a/app/views/wiki/versions.html.haml b/app/views/wiki/versions.html.haml index 2e06877..db96f63 100644 --- a/app/views/wiki/versions.html.haml +++ b/app/views/wiki/versions.html.haml @@ -8,7 +8,7 @@ == radios_to = #{h(@history_to)}; == radios_from = #{h(@history_from)}; -- form_tag diff_course_wiki_instance_url(@course, @wiki_page), :method => :get do += form_tag diff_course_wiki_instance_url(@course, @wiki_page), :method => :get do %button{:type => "submit"}= "Comparar as versões selecionadas" .box %table diff --git a/config/application.rb b/config/application.rb index 4243dba..4e74bf0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,9 @@ end module WikiUFC class Application < Rails::Application + + #set :haml, { :escape_html => false } + config.encoding = "utf-8" config.filter_parameters += [:password] config.active_support.escape_html_entities_in_json = true @@ -76,3 +79,9 @@ module WikiUFC end App = WikiUFC::Application.config + +require "haml" +require "haml/template" +Haml::Template.options[:escape_attrs] = false +Haml::Template.options[:escape_html] = false + diff --git a/config/environment.rb b/config/environment.rb index 8cb7b5c..ce0040c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,3 +3,8 @@ require File.expand_path('../application', __FILE__) # Initialize the rails application WikiUFC::Application.initialize! +# +# Carrega as classes Message e LogEntry. O lazy loading do Rails gera +# problemas se voce definir varias classes por arquivos. +require "./app/models/message.rb" +require "./app/models/log_entry.rb" diff --git a/config/initializers/nasty_hacks.rb.rails2 b/config/initializers/nasty_hacks.rb.rails2 deleted file mode 100644 index 2edbb19..0000000 --- a/config/initializers/nasty_hacks.rb.rails2 +++ /dev/null @@ -1,64 +0,0 @@ -class Fixnum - def is_numeric? - true - end -end - -class String - def is_numeric? - Float self rescue false - end - - def html_escape - ERB::Util::html_escape(self) - end - - %w[auto_link excerpt highlight sanitize simple_format strip_tags truncate word_wrap].each do |method| - eval "def #{method}(*args); ActionController::Base.helpers.#{method}(self, *args); end" - end - - def pretty_url - self.mb_chars.normalize(:kd). - gsub(/[^\x00-\x7F]/n,''). - gsub(/[^a-z._0-9 -]/i,""). - gsub(/ +/,"_"). - downcase.to_s - end -end - -class Array - def add_condition! (condition, conjunction = 'AND') - if String === condition - add_condition!([condition]) - elsif Hash === condition - add_condition!([condition.keys.map { |attr| "#{attr}=?" }.join(' AND ')] + condition.values) - elsif Array === condition - self[0] = "(#{self[0]}) #{conjunction} (#{condition.shift})" unless empty? - (self << condition).flatten! - else - raise "don't know how to handle this condition type" - end - self - end -end - -module ActiveRecord - module Acts - module Versioned - module ClassMethods - def acts_as_paranoid_versioned - # protect the versioned model - self.versioned_class.class_eval do - def self.delete_all(conditions = nil); return; end - end - end - end - end - end -end - -# Carrega as classes Message e LogEntry. O lazy loading do Rails gera -# problemas se voce definir varias classes por arquivos. -#require "#{RAILS_ROOT}/app/models/message.rb" -#require "#{RAILS_ROOT}/app/models/log_entry.rb" - diff --git a/lib/authentication.rb b/lib/authentication.rb index 98b6483..ba37946 100644 --- a/lib/authentication.rb +++ b/lib/authentication.rb @@ -16,7 +16,7 @@ module AuthenticationSystem def login_by_html if !logged_in? flash[:warning] = 'You must be logged in to access this section of the site'[:login_required] - session[:return_to] = request.request_uri + session[:return_to] = request.fullpath redirect_to login_url end end diff --git a/lib/nasty_hacks.rb b/lib/nasty_hacks.rb new file mode 100644 index 0000000..84407b3 --- /dev/null +++ b/lib/nasty_hacks.rb @@ -0,0 +1,75 @@ +class Fixnum + def is_numeric? + true + end +end + +class String + def is_numeric? + Float self rescue false + end + + #def html_escape + # ERB::Util::html_escape(self) + #end + + #%w[auto_link excerpt highlight sanitize simple_format strip_tags truncate word_wrap].each do |method| + # eval "def #{method}(*args); ActionController::Base.helpers.#{method}(self, *args); end" + #end + + def pretty_url + self.mb_chars.normalize(:kd). + gsub(/[^\x00-\x7F]/n,''). + gsub(/[^a-z._0-9 -]/i,""). + gsub(/ +/,"_"). + downcase.to_s + end +end + +#class Array +# def add_condition! (condition, conjunction = 'AND') +# if String === condition +# add_condition!([condition]) +# elsif Hash === condition +# add_condition!([condition.keys.map { |attr| "#{attr}=?" }.join(' AND ')] + condition.values) +# elsif Array === condition +# self[0] = "(#{self[0]}) #{conjunction} (#{condition.shift})" unless empty? +# (self << condition).flatten! +# else +# raise "don't know how to handle this condition type" +# end +# self +# end +#end + +#module ActiveRecord +# module Acts +# module Versioned +# module ClassMethods +# def acts_as_paranoid_versioned +# # protect the versioned model +# self.versioned_class.class_eval do +# def self.delete_all(conditions = nil); return; end +# end +# end +# end +# end +# end +#end + +# disable XSS protection +module CustomHtmlSafe + def html_safe? + true + end +end + +class ActionView::OutputBuffer + include CustomHtmlSafe +end +class ActionView::SafeBuffer + include CustomHtmlSafe +end +class String + include CustomHtmlSafe +end