在我的网站上,用户拥有个人资料,并带有指向他/她个人外部网站的链接。我将这些网站的URL存储在postgresql数据库中,名称为website。当我测试结果时,总是会得到一个像这样的URL:
http://localhost:3000/www.example.com
而不是http://www.example.com
我的视图index.html.erb看起来像这样:
<% provide(:title, 'All projects') %>
<h1>All projects</h1>
<%= will_paginate %>
<ul class="microposts">
<%= render @microposts %>
</ul>
<%= will_paginate %>
我的_micropost.html.erb看起来像这样:
<li>
<span class="title"><%= micropost.title %></span>
<span class="website"><%= link_to micropost.website, micropost.website %></span>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
</li>
我不知道这种情况出了什么问题。如果我在micropost.website之前加上@符号,它会给我一个错误:undefined method `website' for nil:NilClass
有人能帮帮我吗?(我是个 RoR 初学者)
KR, Fabian
<span class="website"><%= link_to micropost.website, micropost.website %></span>
,我会得到一个undefined method `website' for nil:NilClass**错误。 - Fawydundefined method title for nil:NilClass
吗?<span class="title"><%= micropost.title %></span>
- Joe Frambach<%= micropost.title %>
没问题,但如果我改成<%= @micropost.title %>
,我也会得到相同的错误(但这次是针对标题)。 - Fawyd