A
Allan
Hello,
I may be over thinking this situation, so I need another person to
give me a hint. I have an app that has a database of baseball players.
I'm trying to create a feature where you can copy and paste your blog
text, the feature will scan the text and return the text with the
proper html links of my app that point to the player. For example, I'm
a blog writer, I create a entry with one sentence "I am a big fan of
Derek Jeter and Jorge Posada of the Yankees" and I click submit. I'm
basically trying to create this: http://www.baseball-reference.com/friv/link_players.cgi
#This code is taking the sentence and scanning it for two words that
are next to each other that have the first letter capitalized
@full_text = params[:q]
@full_text_array = @full_text.scan(/([A-Z]+[a-zA-Z]* [A-Z]+[a-zA-
Z]*)/)
I then run each name in the array through my ferret search and it will
return proper html link to the player in my DB and insert that into a
new array (@new_link_array)
link = link_to "#{master.nameFirst} #{master.nameLast}",
:controller => :masters,
:action => :show,
layerID => "#{master.playerID}",
:nameFirst => "#{master.nameFirst}".gsub(".",""),
:nameLast => "#{master.nameLast}".gsub(" ", "").gsub("'", "")
Now this is where I'm stuck. I don't understand how to take the
original sentence and replace "Derek Jeter" and "Jorge Posada" with
the linked name.
I've done this:
<%= @full_text.gsub(@full_text_array[0].to_s,
@new_link_array[0]).gsub(@full_text_array[1].to_s, @new_link_array[1])
%>
I run into a few problems here and I'd appreciate a better way to
write and scale this for multiple names (hundreds maybe).
I may be over thinking this situation, so I need another person to
give me a hint. I have an app that has a database of baseball players.
I'm trying to create a feature where you can copy and paste your blog
text, the feature will scan the text and return the text with the
proper html links of my app that point to the player. For example, I'm
a blog writer, I create a entry with one sentence "I am a big fan of
Derek Jeter and Jorge Posada of the Yankees" and I click submit. I'm
basically trying to create this: http://www.baseball-reference.com/friv/link_players.cgi
#This code is taking the sentence and scanning it for two words that
are next to each other that have the first letter capitalized
@full_text = params[:q]
@full_text_array = @full_text.scan(/([A-Z]+[a-zA-Z]* [A-Z]+[a-zA-
Z]*)/)
I then run each name in the array through my ferret search and it will
return proper html link to the player in my DB and insert that into a
new array (@new_link_array)
link = link_to "#{master.nameFirst} #{master.nameLast}",
:controller => :masters,
:action => :show,
layerID => "#{master.playerID}",
:nameFirst => "#{master.nameFirst}".gsub(".",""),
:nameLast => "#{master.nameLast}".gsub(" ", "").gsub("'", "")
Now this is where I'm stuck. I don't understand how to take the
original sentence and replace "Derek Jeter" and "Jorge Posada" with
the linked name.
I've done this:
<%= @full_text.gsub(@full_text_array[0].to_s,
@new_link_array[0]).gsub(@full_text_array[1].to_s, @new_link_array[1])
%>
I run into a few problems here and I'd appreciate a better way to
write and scale this for multiple names (hundreds maybe).