我只是想更新assignment
模式上的名称和说明。我似乎无法弄清楚我做错了什么?
这是我的代码:
def edit
@assignment = Assignment.find_by(id: params[:id])
end
def update
@assignment = Assignment.find_by(id: params[:id])
if @assignment.update_attributes(assignment_params)
flash[:notice] = "Successfully Edited The Assignment"
redirect_to account_assignments_path
else
render 'edit'
end
end
<td><%= button_to "edit assignment", edit_account_assignment_path(assignment), method: :get %>
归于
<%= form_for @assignment, url: account_assignments_path(@assignment) do |form| %>
<%= form.label :name %>:
<%= form.text_field :name %>
<%= form.label :description %>
<%= form.text_field :description %>
<%= form.submit %>
<% end %>
it "edits an assignment" do
user = create(:user)
account = create(:account, users: [user])
assignment = create(:assignment, account_id: account.id)
login_user(user)
visit account_assignments_path
click_button "edit assignment"
expect(current_path).to eq(edit_account_assignment_path(assignment))
fill_in :assignment_name, with: "Edited"
fill_in :assignment_description, with: "Edited Too"
click_button "Update Assignment"
expect(current_path).to eq(account_assignments_path)
expect(page).to have_content("Successfully Edited The Assignment")
end
Creating a assignment assignment management edits an assignment
Failure/Error: click_button "Update Assignment"
ActionController::RoutingError:
No route matches [PATCH] "/account/assignments.1"
答案 0 :(得分:2)
更改此行:
<%= form_for @assignment, url: account_assignments_path(@assignment) do |form| %>
为:
<%= form_for @assignment, url: account_assignment_path(@assignment) do |form| %>