form_for action在编辑操作期间将.id附加到URL - Rails 3

时间:2011-05-12 00:25:46

标签: ruby-on-rails

我有一个表单,当我在编辑操作期间提交时,如果不应该将.id附加到post操作。表单在创建期间正常工作但不更新。

以下是编辑期间的网址发布操作。

http://localhost:3000/members/1/profile.1

继承我的表格

<%= 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 %>

这是此协会的路线。

resources :members do
  resource :profile
  resources :orders
end

这是我在个人资料控制器中的创建,编辑和更新操作

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

什么将profile.id添加到帖子中?

1 个答案:

答案 0 :(得分:1)

我相信这有时会发生嵌套的奇异资源。尝试使用其他form_for格式:

form_for @profile, :url => member_profile_path(@member) do |f|