Commit Graph

113 Commits

Author SHA1 Message Date
Robin Dupret
9b9ec0ded4 Fix a few typos [ci skip] 2015-01-03 16:36:33 +01:00
claudiob
bea61d6670 Better docs for AbstractController
Fixes internal links, adds examples and set fixed-width fonts.

[ci skip]
2014-12-22 03:53:48 +01:00
Joan Karadimov
f6d9b68997 Check if the request variable isn't nil when calling render_to_string
closes #14125
2014-02-20 20:53:47 +02:00
Prem Sichanugrist
103e18c87d Introduce render :body for render raw content
This is an option for sending a raw content back to browser. Note that
this rendering option will unset the default content type and does not
include "Content-Type" header back in the response.

You should only use this option if you are expecting the "Content-Type"
header to not be set. More information on "Content-Type" header can be
found on RFC 2616, section 7.2.1.

Please see #12374 for more detail.
2014-02-18 12:08:36 -05:00
Philipe Fatio
47860b62b3 Require action_view to fix missing constant
Previously, requiring action_view/view_paths did cause an uninitialized
constant error for ENCODING_FLAG, which is defined in action_view.
2014-02-07 17:48:18 +01:00
Carlos Antonio da Silva
618d5317d3 Move the null mime type to request.format
TLDR: always return an object that responds to the query methods from
request.format, and do not touch Mime::Type[] lookup to avoid bugs.

---

Long version:

The initial issue was about being able to do checks like
request.format.html? for request with an unknown format, where
request.format would be nil.

This is where the issue came from at first in #7837 and #8085
(merged in cba05887dc3b56a46a9fe2779b6b228880b49622), but the
implementation went down the path of adding this to the mime type
lookup logic.

This unfortunately introduced subtle bugs, for instance in the merged
commit a test related to send_file had to be changed to accomodate the
introduction of the NullType.

Later another bug was found in #13064, related to the content-type being
shown as #<Mime::NullType:...> for templates with localized extensions
but no format included. This one was fixed in #13133, merged in
43962d6ec50f918c9970bd3cd4b6ee5c7f7426ed.

Besides that, custom handlers were not receiving the proper template
formats anymore when passing through the rendering process, because of
the NullType addition. That was found while migrating an application
from 3.2 to 4.0 that uses the Markerb gem (a custom handler that
generates both text and html emails from a markdown template).

---

This changes the implementation moving away from returning this null
object from the mime lookup, and still fixes the initial issue where
request.format.zomg? would raise an exception for unknown formats due to
request.format being nil.
2013-12-23 16:16:49 -02:00
Vijay Dev
a3b1105ada Merge branch 'master' of github.com:lifo/docrails 2013-12-20 00:10:30 +05:30
Łukasz Strzałkowski
d99dd0af03 Require action_view explicitly in AC::Base 2013-12-08 13:03:41 +01:00
Łukasz Strzałkowski
d8888b94b3 Retain ActionPack dependency on ActionView 2013-12-05 01:02:46 +01:00
Łukasz Strzałkowski
2d3a6a0cb8 Action Pack Variants
By default, variants in the templates will be picked up if a variant is set
and there's a match. The format will be:

  app/views/projects/show.html.erb
  app/views/projects/show.html+tablet.erb
  app/views/projects/show.html+phone.erb

If request.variant = :tablet is set, we'll automatically be rendering the
html+tablet template.

In the controller, we can also tailer to the variants with this syntax:

  class ProjectsController < ActionController::Base
    def show
      respond_to do |format|
        format.html do |html|
          @stars = @project.stars

          html.tablet { @notifications = @project.notifications }
          html.phone  { @chat_heads    = @project.chat_heads }
        end

        format.js
        format.atom
      end
    end
  end

The variant itself is nil by default, but can be set in before filters, like
so:

  class ApplicationController < ActionController::Base
    before_action do
      if request.user_agent =~ /iPad/
        request.variant = :tablet
      end
    end
  end

This is modeled loosely on custom mime types, but it's specifically not
intended to be used together. If you're going to make a custom mime type,
you don't need a variant. Variants are for variations on a single mime
types.
2013-12-04 00:13:16 +01:00
Lauro Caetano
b1b9a0aeca Typos. return -> returns. [ci skip] 2013-12-03 13:31:36 -02:00
Aaron Patterson
267e5c84f9 calculate the ivars to remove in advance as a set and cache them in a
constant.

`view_assigns` can use the precalculated sets and remove instance
variables without allocating any extra arrays
2013-11-06 14:21:40 -08:00
Aaron Patterson
c8b566d54d use a set and reject to avoid array allocations 2013-11-06 14:11:37 -08:00
Aaron Patterson
779cd6ec61 each_with_object on the view_assigns hash 2013-11-06 13:54:15 -08:00
Aaron Patterson
9a4adb4b05 use slice to avoid range allocation 2013-11-06 13:53:52 -08:00
Aaron Patterson
697acc4025 these variables are also private 2013-11-06 13:37:24 -08:00
Aaron Patterson
32e94a488f instance_variables returns symbols, so we should use symbols in our list 2013-11-06 13:24:00 -08:00
Santiago Pastorino
a46fa8df06 Make AC standalone rendering work 2013-09-10 11:01:12 -03:00
José Valim
1385ae138d Remove BasicRendering tests 2013-09-09 16:10:41 -03:00
José Valim
67336ce199 Remove remaining coupling with AV in MimeResponds 2013-09-09 12:33:53 -03:00
José Valim
a41669563b Remove BasicRendering and remove template functionality from AbsC::Rendering 2013-09-09 12:33:53 -03:00
Łukasz Strzałkowski
eddf367b89 Move BasicRendering to AbstractController 2013-09-03 15:03:56 +02:00
Łukasz Strzałkowski
d35cf4b6a0 Make Mime::TEXT default format in AbstractController 2013-09-03 14:58:46 +02:00
Łukasz Strzałkowski
aea02eb430 Move skeleton methods from AV to AbsC
The methods:

 * #render_to_body
 * #render_to_string
 * #_normalize_render

Haven't had anything specyfic to ActionView. This was common code which should belong to AbstractController
2013-09-03 14:57:37 +02:00
Łukasz Strzałkowski
544d0fad3d Return to using protected_instance_variables in AV 2013-09-02 23:18:02 +02:00
Łukasz Strzałkowski
40fcb9e822 Revert "Port all remaining self.protected_instance_variables to class methods"
This reverts commit 7de994fa215e9f4c2856d85034bc4dd7b65d0c01.
2013-09-02 23:18:02 +02:00
Łukasz Strzałkowski
7de994fa21 Port all remaining self.protected_instance_variables to class methods 2013-08-29 12:13:45 +02:00
Łukasz Strzałkowski
7d810049fe Add #rendered_format method to controllers 2013-08-25 11:39:13 +02:00
Łukasz Strzałkowski
1656f58f07 Improve AV::Rendering docs 2013-08-25 11:39:11 +02:00
Łukasz Strzałkowski
d6363aa180 Code formatting & typo fixes 2013-08-25 11:39:09 +02:00
Łukasz Strzałkowski
49608f7b81 Move protected_instance_variables & view_assigns to AbstractController 2013-08-25 11:39:09 +02:00
Łukasz Strzałkowski
8e3413d410 Create AbstractController::Rendering interface
This interface should be use when implementing renderers.
2013-08-25 11:39:09 +02:00
Łukasz Strzałkowski
c90971644a Revert "Rename abstract_controller/rendering. to errors.rb"
This reverts commit 6fe91ec5008838338e54ab8570f7c95ee0cdd8e8.
2013-08-25 11:39:08 +02:00
Łukasz Strzałkowski
cad8a20187 Rename abstract_controller/rendering. to errors.rb
Since all rendering stuff was extracted to AV, the only thing that left was single class with error so file name wasn't relevant anymore
2013-08-25 11:39:08 +02:00
Łukasz Strzałkowski
5759531a95 Move rendering from AP to AV 2013-08-25 11:39:07 +02:00
Carlos Antonio da Silva
0c5552a3dd Fix typos in AP: "overriden" => "overridden" 2013-03-30 15:17:08 -03:00
Anupam Choudhury
a895b4087d Fixed grammar 2013-03-28 16:43:14 +05:30
José Valim
5c1354901e Improve docs for AbsC::Rendering 2013-02-27 08:30:46 -07:00
Yves Senn
4d7f53379a cleanup, remove trailing whitespace within actionpack 2012-10-27 16:03:18 +02:00
Nick Sutterer
1b01ab4959 remove AV.prepare and move all helper-related logic into the controller. this decouples the view since it no longer knows about routes internals.
this is a result of an ongoing discussion at https://github.com/rails/rails/pull/6826.
2012-06-29 11:33:37 +02:00
José Valim
39514af7e7 Merge pull request #5480 from drogus/rendering-issues
Fix for #5440
2012-03-17 11:24:19 -03:00
Sergey Nartimov
5215eed5a3 Symbol#[] method presents in Ruby 1.9 2012-01-07 15:30:36 +03:00
Sergey Nartimov
7d862359d0 get rid of using instance_variable_names method from AS
- instance_variables return symbols in 1.9
- there is instance_variable_defined? method
2012-01-07 14:44:47 +03:00
José Valim
e6bfcc21a8 Remove unecessary config_accessors. 2011-12-24 09:59:28 +01:00
José Valim
efc28a7f70 Some small optimizations and improvements to benchmark code. 2011-12-08 16:39:06 +01:00
José Valim
6e8fe1bf02 TestCase should respect the view_assigns API instead of pulling variables on its own. 2011-10-02 11:29:13 +02:00
José Valim
d42bb68430 More updates to ivars list. 2011-05-06 14:57:25 +02:00
José Valim
894bdbd53d Move variables to underscore format, update protected instance variables list. 2011-05-06 14:57:25 +02:00
José Valim
1632a3a49f More AV::Base cleanup. 2011-05-04 12:07:37 +02:00
José Valim
6afc900191 Move prefixes to view paths as they are now a lookup context dependency. 2011-05-04 11:28:37 +02:00