I have the following special route:
scope '/seller' do
resource :seller_profile, :path => "/profile", :only => [:show, :edit, :update]
end
and the following controller:
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
I use a special route, given that the user must authenticate before accessing the controller, and therefore I can get the seller_profile file from a registered user.
It works like a charm, with only one problem. When I modify the seller_profile file and the validation error, the form is edited again and the errors are displayed correctly. The problem is that the rails add the identifier of the edited record to the URL. For example, when I first edit the entry, the URL is:
http://0.0.0.0:3000/seller/profile/edit
but if the form is submitted with validation errors, the form itself is re-displayed in
http:
where 2 is the identifier of the record being edited.
The form is as follows:
<%= simple_form_for @seller_profile do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.submit %>
<% end %>
, , , ID URL-. ?