Created
October 26, 2012 11:55
-
-
Save cutalion/3958368 to your computer and use it in GitHub Desktop.
Call action from action. Is it good?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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