Ruby on rails 3 错误后渲染编辑时,Rails将id附加到单条路由
我有以下独特的路线:Ruby on rails 3 错误后渲染编辑时,Rails将id附加到单条路由,ruby-on-rails-3,url,routes,Ruby On Rails 3,Url,Routes,我有以下独特的路线: scope '/seller' do resource :seller_profile, :path => "/profile", :only => [:show, :edit, :update] end 以及以下控制器: class SellerProfilesController < ApplicationController before_filter :validate_user_as_seller def show @s
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
但是,如果表单提交时出现验证错误,则表单本身将在下重新显示
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 %>
如前所述,一切都很好,但我会在url中完全屏蔽ID。我该怎么办?我并没有为简单表单做太多工作。但它似乎总是在猜测你的url,就好像它们不是单一的资源一样。您可以提供一个自定义的:
<%= simple_form_for @seller_profile, :url => seller_profile_path do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.submit %>
<% end %>
seller_profile_path do|f|%>
我想这与编辑视图中表单使用的URL有关。你也能提供这部分代码吗?(用于…部分的表格)
<%= simple_form_for @seller_profile, :url => seller_profile_path do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.submit %>
<% end %>