Parametes in the URL

Dear All,

There are two tables one is redemption_list,columns are:
id(int),item_id(char(15)),points_required

the other one is redemption_location,columns are:
id(int),loc_id(char(3)),item_id(char(15)).

…/models/redemption_list.rb
has_many :redemption_locations, :foreign_key => “item_id”

def to_param
item_id
end
…/models/redemption_location.rb
belongs_to :crm_redemption_list, :foreign_key => “item_id”

one redemption has many locations ,the foreign key is item_id, and now i
want to list all the redemptions,

…/controllers/redemption_lists_controller.rb
def index
@redemptions = RedemptionList.all
end

def show
@redemption = RedemptionList.find_by_item_id(params[:id])
end

…/views/redemption_lists/show.html.erb

Item:
<%= @redemption.item_desc %>

The location list of redemption:

<% @redemption.crm_redemption_locations.each do |location| %> <%= radio_button_tag(:location, location.loc_id) %>
<%= location.loc_id%>
<% end %>

at present, i can list all the redemptions,then i click the show button,
to show the details of the redemption and its locations,
there is a error “[SQL Server]The conversion of the varchar value
‘1234567890123 ’ overflowed an int column.: EXEC sp_executesql N’SELECT
[redemption_location].* FROM [redemption_location] WHERE
[crm_redemption_location].[item_id] = 4’”
accturally, the item_id is “1234567890123”, redemption_location_id =4,
and at the same time, the URL looks like this:
http://localhost:3000/redemption_lists/1234567890123%20%20, what is the
meaning of 20%20%?? On the Request part, it shows {“id”=>"1234567890123
"}, i am so confused about this problem, please give me some
advice,thanks very much.

PS: about the parameter on URL, i followed the advice of
#63 Model Name in URL - RailsCasts, i think it is
useful

On 19 January 2012 03:12, Daisy Di [email protected] wrote:

def to_param
item_id
end
…/models/redemption_location.rb
belongs_to :crm_redemption_list, :foreign_key => “item_id”

That should be belongs_to :redemption_list
Also unless you have a very good reason do not use a string column as
a foreign key, use an int and let rails handle it.
Why have you got an item_id column in redemption_list?

@redemption = RedemptionList.find_by_item_id(params[:id])
meaning of 20%20%?? On the Request part, it shows {“id”=>"1234567890123
"}, i am so confused about this problem, please give me some
advice,thanks very much.

I am pretty sure the fundamental problem stems from the fact that
item_id is a string instead of an int. Since it must match the id
column of redemption_list this does not make sense.

Colin