Difference between revisions of "Typo"

From Wiki2
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
====typo====
====typo====
What I know so far
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
from /config/routes.rb - admin/(things in w are admin controllers) ex: /admin/content sends you to admin/content_controller.rb
Line 10: Line 10:
   end
   end


  so http://salty-castle-8378.herokuapp.com/admin/content/edit/1 takes you to  
so http://salty-castle-8378.herokuapp.com/admin/content/edit/1 takes you to  


   def edit
   def edit
Line 27: Line 27:
     @article = Article.get_or_build_article(id)
     @article = Article.get_or_build_article(id)
     @article.text_filter = current_user.text_filter if current_user.simple_editor?
     @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.keywords = Tag.collection_to_string @article.tags
     @article.attributes = params[:article]
     @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  
       
    render 'new'
     @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
  end
to understand rendering I went here: http://guides.rubyonrails.org/layouts_and_rendering.html 


    if request.post?
render 'new' in admin/content_controller.rb takes you to /views/admin/content/new.html.erb
      set_article_author
:partials views start with _ . when you see 'render a/b' while inside a view it looks for views/a/_b.html.erb
      save_attachments
  <% @page_heading = _('New article') %>
     
  <%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %>
      @article.state = "draft" if @article.draft
which sends you to render views/admin/shared/_edit.html .erb


      if @article.save
  <% className = form_action.delete(:class) %>
        destroy_the_draft unless @article.draft
  <%= form_tag(form_action, :id => "#{form_type}_form", :enctype => "multipart/form-data", :class => className) do %>
        set_article_categories
     <%= render :partial => "form" %>
        set_the_flash
  <% end %>
        redirect_to :action => 'index'
You would think that would need _form.html.erb to be in /views/admin/shared but actually it is in /views/admin/content???? How does rails know to take you there? I guess when /admin/shared/edit gets called it doesn't change the directory so when it saysto render 'form' it is the _form.html.erb that is in the directory new was in ie /admin/content.
        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

Latest revision as of 15:04, 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?
   ...
   @article.keywords = Tag.collection_to_string @article.tags
   @article.attributes = params[:article]
   @article.published_at = DateTime.strptime(params[:article][:published_at], "%B %e, %Y %I:%M %p GMT%z").utc rescue 
   render 'new'
 end

to understand rendering I went here: http://guides.rubyonrails.org/layouts_and_rendering.html

render 'new' in admin/content_controller.rb takes you to /views/admin/content/new.html.erb

partials views start with _ . when you see 'render a/b' while inside a view it looks for views/a/_b.html.erb
 <% @page_heading = _('New article') %>
 <%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %>

which sends you to render views/admin/shared/_edit.html .erb

 <% className = form_action.delete(:class) %>
 <%= form_tag(form_action, :id => "#{form_type}_form", :enctype => "multipart/form-data", :class => className) do %>
   <%= render :partial => "form" %>
 <% end %>

You would think that would need _form.html.erb to be in /views/admin/shared but actually it is in /views/admin/content???? How does rails know to take you there? I guess when /admin/shared/edit gets called it doesn't change the directory so when it saysto render 'form' it is the _form.html.erb that is in the directory new was in ie /admin/content.