我已经在heroku上构建了一个小而简单的rails应用程序,您必须通过创建配置文件以用户身份注册,之后您可以输入地址或邮政编码以查找附近最近的健身房,触发google places / geocoder api并为您带来一些结果。 我的问题是,在尝试CRUD我的应用程序时,我无法获得U,基本上是更新工作。我将在下面粘贴我的代码,因为你会看到我把一个binding.pry直接在rails控制台中测试它,看看我的代码是否正确它是否有效,我能够编辑用户的信息然后当我进入psql并查看我的数据库时更新。但是尝试使用浏览器进行更新不起作用。
这是在我的users_controller.rb文件中:
def update
@user = User.find(params[:id])
# binding.pry
@user.update(name: params[:name], password: params[:password], email: params[:email], zipcode: params[:zipcode])
redirect_to '/users'
端
This is the template code:
<h4 id="edit"> Edit your profile below: </h4>
<form action="/users/<%= @user.id%>" method="POST">
<div id="label">
<label>
<input id="one" name="name" placeholder="Edit name"/>
</label>
<label>
<input id="two" name="email" placeholder="Edit email"/>
</label>
<br>
<br>
<label>
<input id="three" name="password" placeholder="Edit password"/>
</label>
<label>
<input id="four" name="zipcode" placeholder="Edit zipcode"/>
</label>
</div>
<input name="_method" value="PUT" type="hidden" />
<input name="authenticity_token" value="<%= form_authenticity_token()%>" type="hidden">
<div id="update">
<br>
<button id="update">Update your profile</button>
</div>
</form>
路线工作,我被带到我设置的确认页面,但是当我尝试使用我更新的信息登录时,旧信息仍然存在。没有显示任何错误阻止我在应用程序中执行任何操作。非常感谢任何帮助,谢谢!
我在终端中看到了这些错误:
答案 0 :(得分:0)
解决了我使用了RichadAE的建议并查看了我的终端的日志以查看错误消息,我看到其中一个错误是当我更新用户信息时,我是只是更新名称或zip用于测试目的,这很好,但因为我正在使用gem&#39; validates_email_format_of&#39;电子邮件字段不能留空,即使更新否则会破坏我的代码,我试图编辑名称并填写电子邮件输入字段以满足要求,它工作!谢谢你的帮助!!