3
我有以下的奇异路径:Rails的附加ID奇异路径渲染错误后,编辑时
scope '/seller' do
resource :seller_profile, :path => "/profile", :only => [:show, :edit, :update]
end
及以下控制器:
class SellerProfilesController < ApplicationController
before_filter :validate_user_as_seller
def show
@seller_profile = current_user.seller_profile
end
def edit
@seller_profile = current_user.seller_profile
end
def update
@seller_profile = current_user.seller_profile
if @seller_profile.update_attributes(params[:seller_profile])
redirect_to(seller_profile_path, :notice => 'Profile was successfully updated.')
else
render :action => "edit"
end
end
end
我用一个单一的途径给予用户必须在获得访问控制器之前进行身份验证,因此我可以从登录用户获取seller_profile。
这种方式就像一个魅力,只有一个问题。当我编辑seller_profile并发生验证错误时,表单再次被编辑并且错误显示正确。问题在于rails会将URL添加到编辑记录的ID中。例如, 当我第一次编辑记录,网址是:
http://0.0.0.0:3000/seller/profile/edit
但如果窗体验证错误提交,窗体本身在
http://0.0.0.0:3000/seller/profile.2
重新显示其中2为ID正在编辑的记录。
的格式如下:
<%= simple_form_for @seller_profile do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.submit %>
<% end %>
一切,说,伟大的工程,但我会完全屏蔽的ID在URL中。我该怎么办?
我想这与您在编辑视图中用于表单的URL有关。你能否提供这部分代码? ('form_for' ...部分) – Kris 2011-05-24 13:25:36
添加了上面的表单代码 – Topo 2011-05-24 21:33:51
任何人都知道吗? – Syl 2012-10-18 17:03:38