If I have several controller actions which have this same line of code
(or
more), how can I DRY up the line without running into complaints about
redirecting or rendering only once? If I put the line in another method
in
my controller, won’t it think I’m redirecting?
I want to dry up lines like this: @listing = Listing.find(params[:id])
def customerview @listing = Listing.find(params[:id])
render :action => ‘edit’
end
def view @listing = Listing.find(params[:id])
render :action => ‘edit’
end
def edit @listing = Listing.find(params[:id])
render :action => ‘edit’
end
If I have several controller actions which have this same line of code
(or more), how can I DRY up the line without running into complaints
about redirecting or rendering only once? If I put the line in another
method in my controller, won’t it think I’m redirecting?
I want to dry up lines like this: @listing = Listing.find(params[:id])
You could use a before_filter:
class MyController < ApplicationController
before_filter :find_listing
def customerview
render :action => ‘edit’
end
def view
render :action => ‘edit’
end
def edit
end
private
def find_listing @listing = Listing.find(params[:id])
end
end