Difference between revisions of "Cs169x"
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
====lecture 12 - caching==== | |||
:bullet and rails_index are gems to help | |||
:new_relic for scaling | |||
====lecture 11==== | |||
:internal monitoring - New Relic, pingdom, airbrake, google analytics, god, monit, nagios, | |||
:Capistrano for deploying rails app | |||
:gotto do CI continuos integration tests | |||
:use autotest | |||
{{:Typo}} | |||
http://sitebuilt.net/images/routes-helpers.PNG | |||
Inspect database schema | |||
rakedb:schema:dump | |||
Create a model interaction diagram automatically | |||
gem install railroady | |||
http://salty-castle-8378.herokuapp.com admin tv8J31j oZ1XktJ now 6j | |||
Recall Rails Cookery #2: adding new feature == new route+new controller method+new view | |||
"string", %Q{string}, 'string', %q{string} | "string", %Q{string}, 'string', %q{string} | ||
a=41 ; "The answer is #{a+1}" | a=41 ; "The answer is #{a+1}" |
Latest revision as of 14:52, 14 September 2013
lecture 12 - caching
- bullet and rails_index are gems to help
- new_relic for scaling
lecture 11
- internal monitoring - New Relic, pingdom, airbrake, google analytics, god, monit, nagios,
- Capistrano for deploying rails app
- gotto do CI continuos integration tests
- use autotest
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.
Inspect database schema
rakedb:schema:dump
Create a model interaction diagram automatically
gem install railroady
http://salty-castle-8378.herokuapp.com admin tv8J31j oZ1XktJ now 6j
Recall Rails Cookery #2: adding new feature == new route+new controller method+new view
"string", %Q{string}, 'string', %q{string} a=41 ; "The answer is #{a+1}"
- match a string against a regexp:
"fox@berkeley.EDU" =~ /(.*)@(.*)\.edu$/i /(.*)@(.*)\.edu$/i =~ "fox@berkeley.EDU"
- If no match, value is false
- If match, value is non-false, and $1...$n capture
parenthesized groups ($1 == 'fox', $2 == 'berkeley') /(.*)$/i or %r{(.*)$}i or Regexp.new('(.*)$', Regexp::IGNORECASE)
- a.b means: call method b on object a
- hashes
h = {"stupid" => 1, :example=> "foo" } h.has_key?("stupid") # => true h["not a key"] # => nil h.delete(:example) # => "foo"