Typo

From Wiki2
Revision as of 15:04, 28 August 2013 by Tim (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.