Ruby code refactoring

Hi,

I have 4 actions in my controller and I have some conditions to be
checked inside each action. what is the best way to do so? For Eg. the
condition to be checked for each action is below

if params[:id] == $boy.id
@rec = $boy.name
elsif params[:id] == $girl.id
@rec = $girl.name
else
render :json=>{“Error”=> “Person with #{params[:id]} does not
exists”} and return
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs