form_for action has .id appended to URL during edit action - Rails 3
I have a form where when I submit during an edit action has the .id appended to the post action when it shouldn't. The form works correctly during create but not update.
Here's the URL post action during edit.
http://localhost:3000/members/1/profile.1
Heres my form
<%= form_for([@member, @profile]) do |f| %>
<%= f.label :first_name %><br />
<%= f.text_field :first_name, {:class => "txt-field-short"} %><br /><br />
<%= f.label :last_name %><br />
<%= f.text_field :last_name, {:class => "txt-field-short"} %><br /><br />
<p><%= submit_tag "Create Profile" %></p>
<% end %>
This is my route for this association.
resources :members do
resource :profile
resources :orders
end
Here's my create, edit and update actions in my profiles controller
def create
@member = current_member
@profile = @member.build_profile(params[:profile])
respond_to do |format|
if @profile.save
format.html { redirect_to(member_profile_path, :notice => 'Profile was successfully created.') }
else
format.html { render :action => "new" }
end
end
end
def edit
@member = current_member
@profile = @member.profile
end
def update
@member = current_member
@profile = @member.profile
respond_to do |format|
if @profile.update_attributes(params[:profile])
format.html { redirect_to(member_profile_path(@profile), :notice => 'Your profile was successfully updated.') }
else
format.html { render :action => "edit" }
end
end
end
What's adding the profile.id to开发者_JS百科 the post action?
I believe this can sometimes happen with nested singular resources. Try using a different form_for
format:
form_for @profile, :url => member_profile_path(@member) do |f|
精彩评论