Permalink
Browse files

allow :format option for #render in Rails 3.1 to set a different temp…

…late format (e.g. :format => :json).
  • Loading branch information...
1 parent 5a6caf9 commit 32d1dfcfa06ba516152bcd1364e6ed554c4d24f8 @apotonick apotonick committed Jun 28, 2011
Showing with 4 additions and 1 deletion.
  1. +1 −0 lib/cell/rails.rb
  2. +2 −0 lib/cell/rails3_1_strategy.rb
  3. +1 −1 test/rails/render_test.rb
View
@@ -76,6 +76,7 @@ def self.controller_path
# +:file+:: Specifies the name of the file template to render.
# +:nothing+:: Doesn't invoke the rendering process.
# +:state+:: Instantly invokes another rendering cycle for the passed state and returns. You may pass arbitrary state-args to the called state.
+ # +:format+:: Sets a different template format, e.g. +:json+.
#
# Example:
# class MusicianCell < ::Cell::Base
@@ -19,6 +19,8 @@ def view_context_class
private
def process_opts_for(opts, state)
opts[:action] = opts[:view] || state
+
+ lookup_context.formats = opts.delete(:format) if opts[:format]
end
end
end
@@ -16,7 +16,7 @@ def play; render; end
BassistCell.class_eval do
def play; render :format => :js; end
end
- assert_equal "alert(\"Doo\");", render_cell(:bassist, :play)
+ assert_equal "alert(\"Doo\");\n", render_cell(:bassist, :play)
end
should "also render alternative engines, like haml" do

0 comments on commit 32d1dfc

Please sign in to comment.