Forum: Ruby Ruby code refactoring

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ecec81af7caddc8730eee285475df4da?d=identicon&s=25 ruby rails (rubyonrails)
on 2014-04-22 07:14
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 topic is locked and can not be replied to.