Skip to content

Commit

Permalink
Added accessors to logger, params, response, session, and headers fro…
Browse files Browse the repository at this point in the history
…m the view, so you can write <% logger.info "stuff" %> instead of <% @logger.info "others" %> -- more consistent with the preferred way of accessing these attributes and collections from the controller

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1307 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed May 19, 2005
1 parent 68cdcf5 commit aa20834
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Added accessors to logger, params, response, session, and headers from the view, so you can write <% logger.info "stuff" %> instead of <% @logger.info "others" %> -- more consistent with the preferred way of accessing these attributes and collections from the controller

* Added support for POST data in form of YAML or XML, which is controller through the X-POST_DATA_MARSHAL header. Example request:

X-POST_DATA_MARSHAL: xml
Expand Down
2 changes: 2 additions & 0 deletions actionpack/lib/action_view/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class Base
attr_reader :first_render
attr_accessor :base_path, :assigns, :template_extension
attr_accessor :controller

attr_reader :logger, :params, :response, :session, :headers

# Turn on to cache the reading of templates from the file system. Doing so means that you have to restart the server
# when changing templates, but that rendering will be faster.
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def hello_in_a_string
@customers = [ Customer.new("david"), Customer.new("mary") ]
render_text "How's there? #{render_to_string("test/list")}"
end

def accessing_params_in_template
render_template "Hello: <%= params[:name] %>"
end

def rescue_action(e) raise end

Expand Down Expand Up @@ -200,6 +204,12 @@ def test_nested_rendering
assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
end

def test_accessing_params_in_template
@request.action = "accessing_params_in_template"
@request.query_parameters[:name] = "David"
assert_equal "Hello: David", process_request.body
end

private
def process_request
TestController.process(@request, @response)
Expand Down

0 comments on commit aa20834

Please sign in to comment.