나는 you.py의 "lastfm"보석을 사용하여 last.fm에서 동적 데이터를 가져 오려고 노력했습니다. 데이터 가져 오기는 훌륭하게 작동합니다. 그러나 레일은 역동적 인 부분을 좋아하지 않는 것처럼 보입니다. 지금, 나는 도우미 폴더에 "HomeHelper"(레일 응용 프로그램을 만드는 동안 발생)라는 도우미 모듈에 코드를 추가 한 :Rails3 도우미 및 동적 내용
module HomeHelper
@@lastfm = Lastfm.new(key, secret)
@@wesRecent = @@lastfm.user.get_recent_tracks(:user => 'weskey5644')
def _album_art_helper
trackHash = @@wesRecent[0]
medAlbumArt = trackHash["image"][3]
if medAlbumArt["content"] == nil
html = "<img src=\"/images/noArt.png\" height=\"auto\" width=\"150\" />"
else
html = "<img src=#{medAlbumArt["content"]} height=\"auto\" width=\"150\" />"
end
html.html_safe
end
def _recent_tracks_helper
lfartist1 = @@wesRecent[0]["artist"]["content"]
lftrack1 = @@wesRecent[0]["name"]
lfartist1 = @@wesRecent[1]["artist"]["content"]
lftrack1 = @@wesRecent[1]["name"]
htmltrack = "<div class=\"lastfm_recent_tracks\">
<div class=\"lastfm_artist\"><p>#{lfartist1 = @@wesRecent[0]["artist"]["content"]}</p></div>
<div class=\"lastfm_trackname\"><p>#{lftrack1 = @@wesRecent[0]["name"]}</p></div>
<div class=\"lastfm_artist\"><p>#{lfartist2 = @@wesRecent[1]["artist"]["content"]}</p></div>
<div class=\"lastfm_trackname\"><p>#{lftrack2 = @@wesRecent[1]["name"]}</p></div>
</div>
"
htmltrack.html_safe
end
end
내가 각 부분 작성에 추가 내 색인 페이지 :
<div class="album_art"><%= render "album_art" %></div>
<div id="nowplayingcontain"><%= render "recent_tracks" %></div>
우수함,이 내가 원하는 같은 페이지에서 내가 필요로하는 데이터와 디스플레이를 얻는다; 그러나, 그것은 last.fm에 따라 노래가 바뀌면 서버를 다시 시작하지 않으면 내 사이트에없는 것으로 보입니다.
나는 이것을 Phusion Gassenger와 WEBrick을 사용하여 테스트했으며 두 가지 모두에서이를 수행 한 것으로 보입니다. 나는 이것이 특정 페이지의 캐싱에 관한 문제일지도 모른다고 생각 했으므로 캐싱 해킹 (caching hacks)을 시도하여 페이지를 다시 만료시켰다. 이것은 도움이되지 못했습니다.
그런 다음이 코드를 도우미 파일에 고정하는 것이 최상의 해결 방법이 아닐 수도 있습니다. 도우미가 동적 콘텐츠를 얼마나 잘 처리하는지 잘 모르겠습니다. 이 같은. 누군가가 이것에 대한 통찰력을 가지고 있다면, 끝내 !! 모두에게 감사드립니다!
왜이 경우 모두'@@ '를 사용하고 있습니까? –