Rails 3 global render
Is there a way to tell an entire controller to render a particular partial or text?
Example:
class PageNotesController < ApplicationController
render :text => "Testing"
def index
@notes = PageNotes.all
end
def show
@note = PageNotes.find(params[:id])
end
def create
@note = PageNotes.create(params[:note])
end
end
开发者_StackOverflow中文版
Now obviously I can go into each individual method and tell it to render something, but I was just curious to know if this is possible.
Thanks in advance!
You could do this. I'm unsure why you'd want to, but here's how.
class PageNotesController < ApplicationController
before_filter :write_out_testing
...
protected
def write_out_testing
render :text=>"Testing
false #do not execute the action originally requested.
end
end
you can tell an entire controller to render a layout.
layout 'some_layout'
if you want a controller to render the same action then you can create one action and pass it different options and find results by params conditions.
to explicitly answer your question. I don't know.
精彩评论