pikitgb
10/19/2016 - 1:37 AM

something_like_this.rb

service.rb (model)

def plan_services() 
  [ [‘1000’, ‘$10 CMS’], [X, Y], [_, _], … ] <- make a loop into this ary to see who is [1000, ?].last
end

def get_display_service(price)
  self.plan_services().each { |s| #<-sub array 
      return s.last if s.first.to_s == price.to_s
  }
  nil
end


helper_file

whatever it give you the array function
def helper_method
   Service.plans_services()
end

controller.rb
def create
   @service = Service.new(params[:service]) # or set_service with params.permit
	@service.service = Service.get_display_service(params[:service][:price])
end