views:

524

answers:

2

I'm using the following code in the view which I got from

http://www.igvita.com/2006/10/20/adding-social-bookmarks-in-rails/

This is the pastie code

But I get the following error:

TypeError in Pages#show
Showing app/views/pages/show.html.erb where line #26 raised:
can’t modify frozen string
Extracted source (around line #26):
23: Twitter
24: Facebook
25:
26: <% current_uri = u(request.protocol << request.host_with_port << request.request_uri)
27: title = u(@title)
28:
29: bookmarklets = {
============

When I replace with this

current_uri = u(request.protocol << request.host_with_port << request.request_uri)

The frozen string error is gone but the link is not parsed. i.e. the link is rendered as follows:

http://digg.com/submit?phase=2&amp;url={{url}}&amp;title={{url_encoded_title}}

Well, I asked at the comment of the article, but couldn't get any reply. So, I'm asking it here.

Thanks

A: 

In your comment you say you have a helper method named title. That's probably causing a name collision with the title variable.

Rename your title variable to page_title. Change it at the top, before the list of sites, and at the bottom, where it's generating the links.

Sarah Mei
A: 

Alternatively... why do you need to use "<<" why not just "+". It could be that the << is trying to add the host_with_port into the array that is holding the protocol string (ie it's modifying the frozen string called "protocol", instead of just adding the two together) and the same with the request_uri string into host_with_port.

Just use + for concatenation and they will stop trying to modify the strings and just add them together before going through u() eg:

current_uri = u(request.protocol + request.host_with_port + request.request_uri)
Taryn East