Skip to content

Instantly share code, notes, and snippets.

@cutalion
Created October 26, 2012 11:55
Show Gist options
  • Save cutalion/3958368 to your computer and use it in GitHub Desktop.
Save cutalion/3958368 to your computer and use it in GitHub Desktop.
Call action from action. Is it good?
class FirstController < ApplicationController
def edit
prepare_model_for_form
end
def update
current_user.attributes = params[:user]
current_user.validates_email!
if current_user.save
redirect_to root_path
else
prepare_model_for_form
render :edit
end
end
private
def prepare_model_for_form
current_user.build_institution unless current_user.institution
2.times { current_user.fields_of_interests.build }
2.times { current_user.fields_of_studies.build }
end
end
class SecondController < ApplicationController
def edit
prepare_model_for_form
render :edit
end
def update
current_user.attributes = params[:user]
current_user.validates_email!
if current_user.save
redirect_to root_path
else
edit
end
end
private
def prepare_model_for_form
current_user.build_institution unless current_user.institution
2.times { current_user.fields_of_interests.build }
2.times { current_user.fields_of_studies.build }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment