Difference between revisions of "Typo"
From Wiki2
Line 8: | Line 8: | ||
match "/admin/#{i}", :to => "admin/#{i}#index", :format => false | match "/admin/#{i}", :to => "admin/#{i}#index", :format => false | ||
match "/admin/#{i}(/:action(/:id))", :to => "admin/#{i}", :action => nil, :id => nil, :format => false | match "/admin/#{i}(/:action(/:id))", :to => "admin/#{i}", :action => nil, :id => nil, :format => false | ||
end | |||
so http://salty-castle-8378.herokuapp.com/admin/content/edit/1 takes you to | |||
def edit | |||
@article = Article.find(params[:id]) | |||
unless @article.access_by? current_user | |||
redirect_to :action => 'index' | |||
flash[:error] = _("Error, you are not allowed to perform this action") | |||
return | |||
end | |||
new_or_edit | |||
end | |||
def new_or_edit | |||
id = params[:id] | |||
id = params[:article][:id] if params[:article] && params[:article][:id] | |||
@article = Article.get_or_build_article(id) | |||
@article.text_filter = current_user.text_filter if current_user.simple_editor? | |||
@post_types = PostType.find(:all) | |||
if request.post? | |||
if params[:article][:draft] | |||
get_fresh_or_existing_draft_for_article | |||
else | |||
if not @article.parent_id.nil? | |||
@article = Article.find(@article.parent_id) | |||
end | |||
end | |||
end | |||
@article.keywords = Tag.collection_to_string @article.tags | |||
@article.attributes = params[:article] | |||
# TODO: Consider refactoring, because double rescue looks... weird. | |||
@article.published_at = DateTime.strptime(params[:article][:published_at], "%B %e, %Y %I:%M %p GMT%z").utc rescue Time.parse(params[:article][:published_at]).utc rescue nil | |||
if request.post? | |||
set_article_author | |||
save_attachments | |||
@article.state = "draft" if @article.draft | |||
if @article.save | |||
destroy_the_draft unless @article.draft | |||
set_article_categories | |||
set_the_flash | |||
redirect_to :action => 'index' | |||
return | |||
end | |||
end | |||
@images = Resource.images_by_created_at.page(params[:page]).per(10) | |||
@resources = Resource.without_images_by_filename | |||
@macros = TextFilter.macro_filters | |||
render 'new' | |||
end | end |
Revision as of 13:17, 28 August 2013
typo
What I know so far
from /config/routes.rb - admin/(things in w are admin controllers) ex: /admin/content sends you to admin/content_controller.rb
# Admin/XController %w{advanced cache categories comments content profiles feedback general pages resources sidebar textfilters themes trackbacks users settings tags redirects seo post_types }.each do |i| match "/admin/#{i}", :to => "admin/#{i}#index", :format => false match "/admin/#{i}(/:action(/:id))", :to => "admin/#{i}", :action => nil, :id => nil, :format => false end
so http://salty-castle-8378.herokuapp.com/admin/content/edit/1 takes you to
def edit @article = Article.find(params[:id]) unless @article.access_by? current_user redirect_to :action => 'index' flash[:error] = _("Error, you are not allowed to perform this action") return end new_or_edit end
def new_or_edit id = params[:id] id = params[:article][:id] if params[:article] && params[:article][:id] @article = Article.get_or_build_article(id) @article.text_filter = current_user.text_filter if current_user.simple_editor?
@post_types = PostType.find(:all) if request.post? if params[:article][:draft] get_fresh_or_existing_draft_for_article else if not @article.parent_id.nil? @article = Article.find(@article.parent_id) end end end
@article.keywords = Tag.collection_to_string @article.tags @article.attributes = params[:article] # TODO: Consider refactoring, because double rescue looks... weird. @article.published_at = DateTime.strptime(params[:article][:published_at], "%B %e, %Y %I:%M %p GMT%z").utc rescue Time.parse(params[:article][:published_at]).utc rescue nil
if request.post? set_article_author save_attachments @article.state = "draft" if @article.draft
if @article.save destroy_the_draft unless @article.draft set_article_categories set_the_flash redirect_to :action => 'index' return end end
@images = Resource.images_by_created_at.page(params[:page]).per(10) @resources = Resource.without_images_by_filename @macros = TextFilter.macro_filters render 'new' end