diff options
Diffstat (limited to 'guides')
-rw-r--r-- | guides/rails_guides/helpers.rb | 2 | ||||
-rw-r--r-- | guides/rails_guides/kindle.rb | 18 | ||||
-rw-r--r-- | guides/rails_guides/markdown.rb | 3 | ||||
-rw-r--r-- | guides/source/action_cable_overview.md | 6 | ||||
-rw-r--r-- | guides/source/active_model_basics.md | 7 | ||||
-rw-r--r-- | guides/source/caching_with_rails.md | 24 | ||||
-rw-r--r-- | guides/source/configuring.md | 24 | ||||
-rw-r--r-- | guides/source/getting_started.md | 2 | ||||
-rw-r--r-- | guides/source/upgrading_ruby_on_rails.md | 2 | ||||
-rw-r--r-- | guides/w3c_validator.rb | 2 |
10 files changed, 63 insertions, 27 deletions
diff --git a/guides/rails_guides/helpers.rb b/guides/rails_guides/helpers.rb index c7d3a38ba9..888b51b1ef 100644 --- a/guides/rails_guides/helpers.rb +++ b/guides/rails_guides/helpers.rb @@ -19,7 +19,7 @@ module RailsGuides end def documents_flat - documents_by_section.flat_map {|section| section["documents"]} + documents_by_section.flat_map { |section| section["documents"] } end def finished_documents(documents) diff --git a/guides/rails_guides/kindle.rb b/guides/rails_guides/kindle.rb index 675df8e55b..6fb8183cb1 100644 --- a/guides/rails_guides/kindle.rb +++ b/guides/rails_guides/kindle.rb @@ -19,7 +19,7 @@ module Kindle puts "=> Arranging html pages in document order" toc = File.read("toc.ncx") doc = Nokogiri::XML(toc).xpath("//ncx:content", "ncx" => "http://www.daisy.org/z3986/2005/ncx/") - html_pages = doc.select {|c| c[:src]}.map {|c| c[:src]}.uniq + html_pages = doc.select { |c| c[:src] }.map { |c| c[:src] }.uniq generate_front_matter(html_pages) @@ -37,13 +37,13 @@ module Kindle def generate_front_matter(html_pages) frontmatter = [] - html_pages.delete_if {|x| + html_pages.delete_if { |x| if x =~ /(toc|welcome|credits|copyright).html/ frontmatter << x unless x =~ /toc/ true end } - html = frontmatter.map {|x| + html = frontmatter.map { |x| Nokogiri::HTML(File.open(x)).at("body").inner_html }.join("\n") @@ -56,7 +56,7 @@ module Kindle h2["id"] = h2.inner_text.gsub(/\s/, "-") end add_head_section fdoc, "Front Matter" - File.open("frontmatter.html","w") {|f| f.puts fdoc.to_html} + File.open("frontmatter.html","w") { |f| f.puts fdoc.to_html } html_pages.unshift "frontmatter.html" end @@ -67,18 +67,18 @@ module Kindle doc = Nokogiri::HTML(File.open(page)) title = doc.at("title").inner_text.gsub("Ruby on Rails Guides: ", "") title = page.capitalize.gsub(".html", "") if title.strip == "" - File.open("sections/%03d/_section.txt" % section_idx, "w") {|f| f.puts title} + File.open("sections/%03d/_section.txt" % section_idx, "w") { |f| f.puts title } doc.xpath("//h3[@id]").each_with_index do |h3,item_idx| subsection = h3.inner_text - content = h3.xpath("./following-sibling::*").take_while {|x| x.name != "h3"}.map(&:to_html) + content = h3.xpath("./following-sibling::*").take_while { |x| x.name != "h3" }.map(&:to_html) item = Nokogiri::HTML(h3.to_html + content.join("\n")) item_path = "sections/%03d/%03d.html" % [section_idx, item_idx] add_head_section(item, subsection) item.search("img").each do |img| img["src"] = "#{Dir.pwd}/#{img['src']}" end - item.xpath("//li/p").each {|p| p.swap(p.children); p.remove} - File.open(item_path, "w") {|f| f.puts item.to_html} + item.xpath("//li/p").each { |p| p.swap(p.children); p.remove } + File.open(item_path, "w") { |f| f.puts item.to_html } end end end @@ -101,7 +101,7 @@ module Kindle "mobi_outfile" => mobi_outfile } puts document.to_yaml - File.open("_document.yml", "w"){|f| f.puts document.to_yaml} + File.open("_document.yml", "w") { |f| f.puts document.to_yaml } end def add_head_section(doc, title) diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index e6c9fea87e..33563d669c 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -54,7 +54,8 @@ module RailsGuides end def engine - @engine ||= Redcarpet::Markdown.new(Renderer, no_intra_emphasis: true, + @engine ||= Redcarpet::Markdown.new(Renderer, + no_intra_emphasis: true, fenced_code_blocks: true, autolink: true, strikethrough: true, diff --git a/guides/source/action_cable_overview.md b/guides/source/action_cable_overview.md index 02db86888c..118b0b52b2 100644 --- a/guides/source/action_cable_overview.md +++ b/guides/source/action_cable_overview.md @@ -242,10 +242,10 @@ WebNotificationsChannel.broadcast_to( The `WebNotificationsChannel.broadcast_to` call places a message in the current subscription adapter (Redis by default)'s pubsub queue under a separate broadcasting name for each user. For a user with an ID of 1, the broadcasting -name would be `web_notifications_1`. +name would be `web_notifications:1`. The channel has been instructed to stream everything that arrives at -`web_notifications_1` directly to the client by invoking the `received` +`web_notifications:1` directly to the client by invoking the `received` callback. ### Subscriptions @@ -313,7 +313,7 @@ App.cable.subscriptions.create { channel: "ChatChannel", room: "Best Room" }, ```ruby # Somewhere in your app this is called, perhaps # from a NewCommentJob. -ChatChannel.broadcast_to( +ActionCable.server.broadcast( "chat_#{room}", sent_by: 'Paul', body: 'This is a cool chat app.' diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index e834aeadb1..732e553c62 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -416,7 +416,6 @@ the Active Model API. ```ruby class Person include ActiveModel::Model - end ``` @@ -467,7 +466,7 @@ In order to make this work, the model must have an accessor named `password_dige The `has_secure_password` will add the following validations on the `password` accessor: 1. Password should be present. -2. Password should be equal to its confirmation. +2. Password should be equal to its confirmation (provided +password_confirmation+ is passed along). 3. The maximum length of a password is 72 (required by `bcrypt` on which ActiveModel::SecurePassword depends) #### Examples @@ -493,6 +492,10 @@ person.valid? # => false person.password = person.password_confirmation = 'a' * 100 person.valid? # => false +# When only password is supplied with no password_confirmation. +person.password = 'aditya' +person.valid? # => true + # When all validations are passed. person.password = person.password_confirmation = 'aditya' person.valid? # => true diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index cc84ecb216..a1b0029c47 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -512,6 +512,30 @@ class ProductsController < ApplicationController end ``` +Sometimes we want to cache response, for example a static page, that never gets +expired. To achieve this, we can use `http_cache_forever` helper and by doing +so browser and proxies will cache it indefinitely. + +By default cached responses will be private, cached only on the user's web +browser. To allow proxies to cache the response, set `public: true` to indicate +that they can serve the cached response to all users. + +Using this helper, `last_modified` header is set to `Time.new(2011, 1, 1).utc` +and `expires` header is set to a 100 years. + +WARNING: Use this method carefully as browser/proxy won't be able to invalidate +the cached response unless browser cache is forcefully cleared. + +```ruby +class HomeController < ApplicationController + def index + http_cache_forever(public: true) do + render + end + end +end +``` + ### Strong v/s Weak ETags Rails generates weak ETags by default. Weak ETags allow semantically equivalent diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 3aa21b7772..7239105b29 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -402,6 +402,22 @@ The schema dumper adds one additional configuration option: * `config.action_controller.always_permitted_parameters` sets a list of whitelisted parameters that are permitted by default. The default values are `['controller', 'action']`. +* `config.action_controller.enable_fragment_cache_logging` determines whether to log fragment cache reads and writes in verbose format as follows: + + ``` + Read fragment views/v1/2914079/v1/2914079/recordings/70182313-20160225015037000000/d0bdf2974e1ef6d31685c3b392ad0b74 (0.6ms) + Rendered messages/_message.html.erb in 1.2 ms [cache hit] + Write fragment views/v1/2914079/v1/2914079/recordings/70182313-20160225015037000000/3b4e249ac9d168c617e32e84b99218b5 (1.1ms) + Rendered recordings/threads/_thread.html.erb in 1.5 ms [cache miss] + ``` + + By default it is set to `false` which results in following output: + + ``` + Rendered messages/_message.html.erb in 1.2 ms [cache hit] + Rendered recordings/threads/_thread.html.erb in 1.5 ms [cache miss] + ``` + ### Configuring Action Dispatch * `config.action_dispatch.session_store` sets the name of the store for session data. The default is `:cookie_store`; other valid options include `:active_record_store`, `:mem_cache_store` or the name of your own custom class. @@ -518,14 +534,6 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`. * `config.action_view.debug_missing_translation` determines whether to wrap the missing translations key in a `<span>` tag or not. This defaults to `true`. -* `config.action_view.enable_fragment_cache_logging` determines whether to log fragment cache reads and writes like: - - ``` - Read fragment views/v1/2914079/v1/2914079/recordings/70182313-20160225015037000000/d0bdf2974e1ef6d31685c3b392ad0b74 (0.6ms) - ``` - - Default value is false. - ### Configuring Action Mailer There are a number of settings available on `config.action_mailer`: diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 89b1d3ca03..0cb5d81042 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -68,7 +68,7 @@ The Rails philosophy includes two major guiding principles: again, our code is more maintainable, more extensible, and less buggy. * **Convention Over Configuration:** Rails has opinions about the best way to do many things in a web application, and defaults to this set of conventions, rather than - require that you specify every minutiae through endless configuration files. + require that you specify minutiae through endless configuration files. Creating a New Rails Project ---------------------------- diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 2ac5a2188b..8fcbf3ed4b 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -44,7 +44,7 @@ TIP: Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterp ### The Update Task -Rails provides the `app:update` task (`rails:update` on 4.2 and earlier). After updating the Rails version +Rails provides the `app:update` task (`rake rails:update` on 4.2 and earlier). After updating the Rails version in the Gemfile, run this task. This will help you with the creation of new files and changes of old files in an interactive session. diff --git a/guides/w3c_validator.rb b/guides/w3c_validator.rb index f56feeb696..2ce27e2e16 100644 --- a/guides/w3c_validator.rb +++ b/guides/w3c_validator.rb @@ -67,7 +67,7 @@ module RailsGuides def select_only(guides) prefixes = ENV["ONLY"].split(",").map(&:strip) guides.select do |guide| - prefixes.any? {|p| guide.start_with?("./output/#{p}")} + prefixes.any? { |p| guide.start_with?("./output/#{p}") } end end |