Question

I have two Models, ELTeam and Rider which are linked by the attribute ELTeamID.

I am trying to parse the value ELTeamID via the

<%= url_for :action => 'filter_rider_by_team', :id => team.ELTeamId %>

My method is:

def filter_rider_by_team
    rId = @params['id'] 
    rId = rId.sub(/{/,'') 
    rId = rId.sub(/}/,'') 

    #variable
    @riders = Rider.find(:all, :conditions => {'ELTeamId' => '#{rId}'})

    #hardcoded
    #@riders = Rider.find(:all, :conditions => {'ELTeamId' => '3'})

      Rho::Notification.showPopup({
      :message => "Parameter ID: #{@params['id']}, rId: '#{rId}', Riders: #{@riders}",
      :title => "Riders",
      :buttons => ["OK"]
      })
end

If I use the line beneath "variable" I get nothing returned (output of showPopup here), however, if I use the line under #hardcoded I get a Rider returned (output of showPopup here).

What is the correct syntax to pass through the value as a variable?

Was it helpful?

Solution

Assuming you want to do interpolation, use double quotes: "#{rId}", which is equivalent to rId.to_s. Since you seem to have a string as rId, you should just write rId.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top