当前位置: 动力学知识库 > 问答 > 编程问答 >

Rails (now) not liking my jquery script which turned <td> elements into links. "undefined method" error

问题描述:

Here is the erring portion of the view (show.html.erb)

<% @results.each do |r| %>

<tr class="tweets">

<script>

$("td.status").click(function(){

window.location = "http://www.twitter.com/id/status/<%= r.page_id %>";

});

</script>

<td class="user"><img src="<%= r.img_url %>"></td>

<td class="user"><strong><%= r.screen_name %></strong></td>

<td class="user"><%= r.real_name %></td>

<td class="time"><%= r.time_ago %></td>

<td class="status"><%= r.status %></td>

</tr>

<% end %>

Note that when I remove the jquery script all other r.element tags work. The @results object instantiated in this view's controller (called here) calls this script (I'm only showing part of it)

module SimpleTwitter

class Tweet

attr_accessor :img_url, :screen_name, :real_name, :status, :time_ago

def initialize(tweet_hash)

@img_url = tweet_hash['profile_image_url']

@screen_name = tweet_hash['from_user']

@real_name = tweet_hash['from_user_name']

@status = tweet_hash['text']

@page_id = tweet_hash['id']

...(cont)...

There is a lot of complicated (to me anyway) parsing going on here through a series of files, gems, classes, but know that without the jquery script which "linkifies" given elements, all is working well. Previously I used this jquery script without error.

Please let me know if you'd like more information.

EDIT (DOH!) --- here's the error message:

NoMethodError in Searches#show

Showing /home/ddouglas/Develop/twitter_research/app/views/searches/show.html.erb where line #28 raised:

undefined method `page_id' for #<SimpleTwitter::Tweet:0x000000030ee590>

Extracted source (around line #28):

25:

26: <script>

27: $("td.status").click(function(){

28: window.location = "http://www.twitter.com/id/status/<%= r.page_id %>";

29: });

30: </script>

31: <td class="user"><img src="<%= r.img_url %>"></td>

网友答案:

attr_accessor for the Tweet class did not include :page_id

Thanks cheung

分享给朋友:
您可能感兴趣的文章:
随机阅读: