Permalink
Browse files

Remove client_side_validations and cancan

  • Loading branch information...
1 parent 67a5f34 commit d0f0a2080d4f7639d6a589b30e3547297ab591e9 @reyesyang committed Dec 16, 2013
View
@@ -29,7 +29,6 @@ gem 'turbolinks'
gem 'jbuilder', '~> 1.5.1'
gem 'execjs'
-gem 'client_side_validations'
gem 'twitter-bootstrap-rails'
gem 'less-rails'
# gem "acts_as_ferret", :git => "https://github.com/jkraemer/acts_as_ferret.git"
@@ -46,9 +45,6 @@ gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'omniauth-github'
-# permission control
-gem "cancan"
-
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.1.0'
@@ -63,6 +59,7 @@ gem 'rvm-capistrano'
# gem 'ruby-debug'
group :development, :test do
+ gem 'quiet_assets'
gem 'factory_girl_rails'
gem 'pry-rails'
end
View
@@ -29,14 +29,12 @@ GEM
atomic (1.1.13)
bcrypt-ruby (3.1.2)
builder (3.1.4)
- cancan (1.6.10)
capistrano (2.15.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
- client_side_validations (3.2.6)
coderay (1.0.9)
coffee-rails (4.0.0)
coffee-script (>= 2.2.0)
@@ -117,6 +115,8 @@ GEM
slop (~> 3.4)
pry-rails (0.3.2)
pry (>= 0.9.10)
+ quiet_assets (1.0.2)
+ railties (>= 3.1, < 5.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
@@ -183,9 +183,7 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby (~> 3.1.0)
- cancan
capistrano
- client_side_validations
coffee-rails (~> 4.0.0)
execjs
factory_girl_rails
@@ -198,6 +196,7 @@ DEPENDENCIES
omniauth-github
omniauth-google-oauth2
pry-rails
+ quiet_assets
rails (~> 4.0.0)
redcarpet
rvm-capistrano
@@ -7,7 +7,6 @@
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
-//= require rails.validations
//= require global.js
//= require timeago
//= require jquery.autogrowtextarea
@@ -33,7 +33,7 @@ html {
width: 60px;
display: block;
text-indent: -1000px;
- background-image: url('/assets/logo.jpeg');
+ background-image: asset-url('logo.jpeg');
}
#me {
@@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
class ApplicationController < ActionController::Base
protect_from_forgery
- check_authorization
+ skip_before_filter :verify_authenticity_token, :only => :create
helper_method :current_user, :logined?
@@ -12,8 +12,10 @@ def current_user
def logined?
!!current_user
end
-
- rescue_from CanCan::AccessDenied do |exception|
- redirect_to root_url, flash: { error: exception.message }
+
+ private
+
+ def require_admin
+ redirect_to root_path if !(logined? && current_user.admin?)
end
end
@@ -1,12 +1,12 @@
# -*- encoding : utf-8 -*-
class ArticlesController < ApplicationController
+ before_filter :require_admin, only: [:new, :create, :edit, :update, :destroy]
before_filter :load_article_with_tags, only: [:show, :edit]
- load_and_authorize_resource
def index
@articles = current_user && current_user.admin? ?
- @articles.includes(:tags).paginate(:page => params[:page]) :
- @articles.includes(:tags).where("tags.name != 'draft'").paginate(:page => params[:page])
+ Article.includes(:tags).order("articles.id DESC").paginate(:page => params[:page]) :
+ Article.includes(:tags).where("tags.name != 'draft'").order("articles.id DESC").paginate(:page => params[:page])
@page_title = '首页'
@@ -51,6 +51,7 @@ def create
end
def update
+ @article = Article.find params[:id]
respond_to do |format|
if @article.update_attributes(article_params)
format.html { redirect_to(@article, :notice => 'Article was successfully updated.') }
@@ -61,6 +62,7 @@ def update
end
def destroy
+ @article = Article.find params[:id]
@article.destroy
respond_to do |format|
@@ -1,6 +1,4 @@
class SessionsController < ApplicationController
- authorize_resource :class => false
-
def create
omniauth = request.env['omniauth.auth']
auth = Authorization.where(provider: omniauth['provider'], uid: omniauth['uid']).first_or_create do |auth|
@@ -11,16 +9,6 @@ def create
session[:user_id] = auth.user.id
redirect_to root_path
end
-
- def login
- user = User.find_by_name params[:name]
- if user && user.authenticate(params[:password])
- session[:user_id] = user.id
- redirect_to articles_url
- else
- redirect_to root_url
- end
- end
def logout
reset_session
@@ -1,6 +1,5 @@
class TagsController < ApplicationController
before_filter :load_tag_by_name, only: [:show]
- load_and_authorize_resource
def show
@articles = @tag.articles.includes(:tags).paginate(page: params[:page])
@@ -23,5 +22,4 @@ def self.list(user)
def load_tag_by_name
@tag = Tag.find_by_name params[:id]
end
-
end
@@ -1,95 +1,6 @@
# -*- encoding : utf-8 -*-
class UsersController < ApplicationController
- load_and_authorize_resource
-
- # GET /users
- # GET /users.xml
- def index
- @users = User.order(:name)
-
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @users }
- end
- end
-
- # GET /users/1
- # GET /users/1.xml
- def show
- @user = User.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @user }
- end
- end
-
- # GET /users/new
- # GET /users/new.xml
- def new
- @user = User.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @user }
- end
- end
-
- # GET /users/1/edit
- def edit
- @user = User.find(params[:id])
- end
-
- # POST /users
- # POST /users.xml
- def create
- @user = User.new(user_params)
-
- respond_to do |format|
- if @user.save
- format.html { redirect_to(users_url, :notice => 'User #{@user.name} was successfully created.') }
- format.xml { render :xml => @user, :status => :created, :location => @user }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # PUT /users/1
- # PUT /users/1.xml
- def update
- @user = User.find(params[:id])
-
- respond_to do |format|
- if @user.update_attributes(user_params)
- format.html { redirect_to(users_url, :notice => 'User #{@user.name} was successfully updated.') }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # DELETE /users/1
- # DELETE /users/1.xml
- def destroy
- @user = User.find(params[:id])
- @user.destroy
-
- respond_to do |format|
- format.html { redirect_to(users_url) }
- format.xml { head :ok }
- end
- end
-
def about
@page_title = '关于'
end
-
- private
- def user_params
- params.require(:user).permit(:name, :email, :image_url)
- end
end
@@ -1,28 +1,20 @@
# -*- encoding : utf-8 -*-
module ApplicationHelper
def format_text(text, options = {})
- sanitize markdown(link_mentions(text, options[:mention_names]))
+ sanitize markdown(text)
end
def markdown(text)
- markdown_render = Redcarpet::Render::HTML.new :hard_wrap => true, :no_styles => true
+ markdown_render = Redcarpet::Render::HTML.new no_style: true, hard_wrap: true
markdown = Redcarpet::Markdown.new(markdown_render,
- :autolink => true,
- :no_intra_emphasis => true)
+ autolink: true,
+ no_intra_emphasis: true,
+ fenced_code_blocks: true,
+ strikethrough: true,
+ superscript: true)
markdown.render(text.to_s)
end
- def link_mentions(text, mention_names)
- if mention_names && mention_names.any?
- text.gsub(/@(#{mention_names.join('|')})(?![.\w])/) do
- username = $1
- %Q[@<a href="/~#{username}">#{username}</a>]
- end
- else
- text
- end
- end
-
def join_tags(article)
article.tags.map { |tag| "<a href='/articles/tag/#{tag.id}'>#{tag.name}</a>" }.join("; ")
end
View
@@ -1,23 +0,0 @@
-class Ability
- include CanCan::Ability
-
- def initialize(user)
- user ||= User.new
-
- if user.admin?
- can :manage, :all
- else
- can :create, :session
- can :about, User
- can :read, Article
- can :read, Tag
- cannot :show, Article do |article|
- article.draft?
- end
-
- cannot :show, Tag do |tag|
- tag.name == 'draft'
- end
- end
- end
-end
View
@@ -7,8 +7,6 @@ class Article < ActiveRecord::Base
validates :title, :content, :presence => true
- default_scope order('articles.id DESC')
-
self.per_page = 10
@@original_tags = nil
View
@@ -1,8 +1,9 @@
# -*- encoding : utf-8 -*-
class Tag < ActiveRecord::Base
- default_scope :order => 'name'
has_and_belongs_to_many :articles
+ scope :ordered, -> { order('name') }
+
def to_param
name
end
@@ -14,5 +14,5 @@
-if logined? && current_user.admin?
%span.operation
= link_to t('edit'), edit_article_path(article)
- = link_to t('destroy'), article, :confirm => 'Are you sure?', :method => :delete
+ = link_to t('destroy'), article, data: { confirm: 'Are you sure?' }, :method => :delete
.clear
@@ -15,6 +15,7 @@
= link_to t('edit'), edit_article_path(@article)
= link_to t('back'), articles_path
- .article_content= format_text @article.content
+ .article_content
+ ~ format_text @article.content
= render :partial => 'layouts/disque'
@@ -5,11 +5,11 @@
= link_to '吾', '/about'
#passage
- if logined?
- = link_to '注销', logout_path, :confirm => 'Are you sure?', :method => :delete
+ = link_to '注销', logout_path, data: { confirm: 'Are you sure?' }, :method => :delete
%section#aside_tags
- - @tags = Tag.list(current_user)
+ - @tags = Tag.ordered.list(current_user)
- if @tags.any?
%ul.unstyled
- @tags.each do |tag|
@@ -1,5 +1,6 @@
default: &default
secret_token:
+ secret_key_base:
ga_account:
disqus_developer: 1
disqus_shortname:
Oops, something went wrong.

0 comments on commit d0f0a20

Please sign in to comment.