在我的user.rb
文件下的models
中,我定义了一个方法full-name
,并在我的视图中调用了此方法。它引发了我不知道如何解决的这个错误。未定义方法`+'为零:NilClass在Rails中
NoMethodError in Statuses#index
Showing app/views/layouts/application.html.erb where line #24 raised:
undefined method `+' for nil:NilClass
Extracted source (around line #10):
def full_name
first_name + " " + last_name
end
Rails.root:
Application Trace | Framework Trace | Full Trace
app/models/user.rb:10:in `full_name'
app/views/layouts/application.html.erb:24:in `_app_views_layouts_application_html_erb__1801360389632919652_70105866374460'
<li>
<%= link_to current_user.full_name, edit_user_registration_path %>
</li>
'全name'是一个无效的方法名称。你的问题是什么? – sawa