我在定制Devise方法时遇到问题。我想编辑现有的个人资料。但它并没有改变。
这是我的代码
我的控制器:
Type
我的编辑视图
class DashboardController < Users::RegistrationsController::ApplicationController
def index
end
def update
@user = current_user
if @user.update_attributes(user_params)
redirect_to 'index', :notice => "Successfully updated profile."
else
Rails.logger.info(@user.errors.messages.inspect)
render :action => 'edit'
end
end
def edit
end
private
def user_params
params.require(:user).permit(:avatar, :username, :email, :password, :password_confirmation)
end
end
这可能是我的布局代码中的问题,我在其中创建了编辑页面的链接
<div class="container sign-in-up">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<br>
<div class="text-center">
<h1><b>Edit the profile</b> </h2>
<div class="tab-content">
<div class="tab-pane fade in active" id="new">
<fieldset>
<div class="form-group">
<div class="right-inner-addon">
<i class="fa fa-envelope"></i>
<%= form_for current_user, url: edit_dashboard_path(current_user), html: { method: :get, multipart: true } do |f|%>
<div class="home_field " >
<%= f.label :username%>
<br/>
<%= f.text_field :username, autofocus: true, :placeholder => 'Username', class:"form-control input-lg " %>
</div>
<div class="home_field ">
<%= f.label :email %>
<br/>
<%= f.email_field :email, autofocus: true, :placeholder => 'Email' , class:"form-control input-lg" %>
</div>
<div class="home_field ">
<%= f.label :password%>
<br/>
<%= f.password_field :password, :placeholder => 'Password', class:"form-control input-lg"%>
</div>
<div class="home_field ">
<%= f.label :password_confirmation%>
<br/>
<%= f.password_field :password_confirmation,:placeholder => 'Confirm your password' , class:"form-control input-lg"%>
</div>
<div class ="home_field">
<%= f.file_field :avatar %>
<br>
</div>
<div>
</div>
<div class="home_field">
<%= f.submit 'Edit the profile', class: "btn btn-primary btn-lg btn-block btn-group" %>
<br/>
</div>
<% end %>
</fieldset>
答案 0 :(得分:0)
您的表单使用get提交到编辑信息中心,这与您所在的页面相同。相反,您想要更新当前用户:
<%= form_for current_user, html: { multipart: true } do |f|%>
这将默认为您的路线文件中为用户
定义的更新属性和CRUD操作答案 1 :(得分:0)
我建议改变这一行:
<%= form_for current_user, url: edit_dashboard_path(current_user), html: { method: :get, multipart: true } do |f|%>
rake routes
)