Ruby on rails 表单\u for-带错误的重定向
我在视图Ruby on rails 表单\u for-带错误的重定向,ruby-on-rails,redirect,form-for,Ruby On Rails,Redirect,Form For,我在视图settings\info中为(@user)使用form\u: # ./views/settings/info.html.erb <%= form_for(@user) do |f| %> <% if @user.errors.any? %> <% @user.errors.full_messages.each do |msg| %> <li>* <%= msg %><
settings\info
中为(@user)使用form\u:
# ./views/settings/info.html.erb
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
<% end %>
...
<% end %>
# ./controllers/users_controller.rb
def update
@user = User.find(current_user.id)
if @user.update_attributes(params["user"])
....
else
render template: 'settings/info'
end
end
。/views/settings/info.html.erb
*
...
#./controller/users\u controller.rb
def更新
@user=user.find(当前用户id)
如果@user.update_属性(参数[“user”])
....
其他的
渲染模板:“设置/信息”
结束
结束
一切都很好,如果有错误就会显示出来。但是,因为我在settings_controllers.rb的info
action中传递了一些变量,所以我需要将其更改为重定向(有错误)。我该怎么做
提前感谢在重定向的情况下,我通常使用railsflash
对象并直接添加错误
flash[:alert] = @user.errors.full_messages.join(' ')
谢谢我刚刚意识到我不能一个接一个地犯错误。有办法吗?