Ruby on rails 未定义的方法'profile';零级:零级
我的编辑视图中出现错误“未定义nil:NilClass的方法'profile'”。当我更新配置文件记录并在出现错误时重定向到编辑页面时,我在呈现编辑视图时遇到问题。以下是my Profiles controller中的代码:Ruby on rails 未定义的方法'profile';零级:零级,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我的编辑视图中出现错误“未定义nil:NilClass的方法'profile'”。当我更新配置文件记录并在出现错误时重定向到编辑页面时,我在呈现编辑视图时遇到问题。以下是my Profiles controller中的代码: def edit @usermodel = current_usermodel @profile = current_usermodel.profile if current_usermodel.stripe_access_token.blank?
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.profile%>
商业信息
...
@usermodel为零,从控制器看来,情况不应该是这样的尝试添加
@usermodel = current_usermodel
也要更新操作。您应该检查为什么
当前用户模型返回nil
。