【发布时间】:2014-05-23 07:15:01
【问题描述】:
我的编辑视图中出现错误“undefined method `profile' for nil:NilClass”。当我更新我的个人资料记录并在出现错误时重定向到编辑页面时,我遇到了呈现编辑视图的问题。这是我的 Profiles 控制器中的代码:
def edit
@usermodel = current_usermodel
@profile = current_usermodel.profile
if current_usermodel.stripe_access_token.blank?
flash.keep[:error] = "Please, connect your #{view_context.link_to('Stripe Account', usermodel_omniauth_authorize_path(:stripe_connect))} to accept payments".html_safe
end
end
def update
@profile = current_usermodel.profile
respond_to do |format|
if @profile.update_attributes(params[:profile])
format.html { redirect_to @profile, notice: 'Profile was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
在视图中,我有以下形式:
<%= simple_form_for @usermodel.profile do |f| %>
<%= render "pages/error_display", :target => @usermodel.profile %>
</br>
<b>Business Info </b>
...
@usermodel 为 nil,从控制器看来,情况并非如此
【问题讨论】:
-
你应该检查为什么你的
current_usermodel返回nil。
标签: ruby-on-rails ruby-on-rails-4