ruby - Call inner controller actions and send params between them rails -
i'm creating api , want outside can has access update method actualize report. in case there no report want create it. know easy way create inside update method, have create method build wondering if possible call sending params.
i looked around here rails 3: call functions inside controllers or api didn't found solution.
does has better one?
thank in advance.
you should not call action of controller action.
why? because every action of controller defined respond request, has several attributes (such ip, params, session, http headers, etc.). imagine how "weird" call action in controller.
if want "extra logic" not related update action (for example, create), should call protected (accessible via controller & children) method of controller.
in case, this:
class reportscontroller < applicationcontroller def update @report = report.where(id: params[:report_id]).first if @report.nil? create_report(params) else # etc. end end protected def create_report(params) report.create(params) end end
Comments
Post a Comment