Ruby on rails ActionController::RoutingError:没有与[PUT]rspec匹配的路由
我的考试有点问题 这是我的个人资料\u页面\u spec.rb:Ruby on rails ActionController::RoutingError:没有与[PUT]rspec匹配的路由,ruby-on-rails,rspec,Ruby On Rails,Rspec,我的考试有点问题 这是我的个人资料\u页面\u spec.rb: describe "ProfilePages" do subject { page } describe "edit" do let(:user) { FactoryGirl.create(:user) } let(:profile) do FactoryGirl.create(:profile, user: user) end before do login user visit edit_pro
describe "ProfilePages" do
subject { page }
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
let(:profile) do
FactoryGirl.create(:profile, user: user)
end
before do
login user
visit edit_profile_path(profile)
end
it { should have_selector('h2', text: 'Заполните информацию о себе') }
describe "change information" do
let(:new_city) { "Ulan-Bator" }
let(:new_phone) { 1232442 }
let(:new_gamelevel) { "M2" }
let(:new_aboutme) { "nfsfsdfds" }
let(:submit) { "Сохранить" }
before do
fill_in "Город", with: new_city
fill_in "Телефон", with: new_phone
select new_gamelevel, from: "Уровень игры"
fill_in "О себе", with: new_aboutme
click_button submit
end
specify { profile.reload.city.should == new_city }
specify { profile.reload.phone.should == new_phone }
specify { profile.reload.gamelevel.should == new_gamelevel }
specify { profile.reload.aboutme.should == new_aboutme }
end
describe "submitting to the update action" do
before { put edit_profile_path(profile) }
specify { response.should redirect_to(user_path(user)) }
end
end
end
def edit
@profile = current_user.profile
end
def update
@profile = current_user.profile
if @profile.update_attributes(params[:profile])
flash[:success] = "Профиль обновлен!"
redirect_to user_path(current_user)
else
render 'edit'
end
end
这是我的配置文件\u控制器。rb:
describe "ProfilePages" do
subject { page }
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
let(:profile) do
FactoryGirl.create(:profile, user: user)
end
before do
login user
visit edit_profile_path(profile)
end
it { should have_selector('h2', text: 'Заполните информацию о себе') }
describe "change information" do
let(:new_city) { "Ulan-Bator" }
let(:new_phone) { 1232442 }
let(:new_gamelevel) { "M2" }
let(:new_aboutme) { "nfsfsdfds" }
let(:submit) { "Сохранить" }
before do
fill_in "Город", with: new_city
fill_in "Телефон", with: new_phone
select new_gamelevel, from: "Уровень игры"
fill_in "О себе", with: new_aboutme
click_button submit
end
specify { profile.reload.city.should == new_city }
specify { profile.reload.phone.should == new_phone }
specify { profile.reload.gamelevel.should == new_gamelevel }
specify { profile.reload.aboutme.should == new_aboutme }
end
describe "submitting to the update action" do
before { put edit_profile_path(profile) }
specify { response.should redirect_to(user_path(user)) }
end
end
end
def edit
@profile = current_user.profile
end
def update
@profile = current_user.profile
if @profile.update_attributes(params[:profile])
flash[:success] = "Профиль обновлен!"
redirect_to user_path(current_user)
else
render 'edit'
end
end
简介表格:
<%= form_for(@profile) do |f| %>
<%= render 'devise/shared/error_messages', object: f.object %>
<div><%= f.label :city, "Город" %>
<%= f.text_field :city, :autofocus => true %></div>
<div><%= f.label :phone, "Телефон" %>
<%= f.number_field :phone %></div>
<div><%= f.label :gamelevel, "Уровень игры" %>
<%= f.select(:gamelevel,[['Pro', 'Pro'],
['M1', 'M1'],
['M2', 'M2'],
['M3', 'M3']]) %></div>
<div><%= f.label :aboutme,"О себе" %>
<%= f.text_area :aboutme, placeholder: "Немного о себе...",size: " 40x10" %></div>
<div><%= f.submit "Сохранить", class: "btn btn-primary" %></div>
<% end %>
正确%>
在firefox中,我可以发送我的表单,数据将发生变化。但在我的规范中,我有一个错误:
ActionController::RoutingError:没有与[PUT]匹配的路由
耙道:
编辑_profile GET/profiles/:id/edit(:format)profile#编辑
配置文件放置/配置文件/:id(:格式)配置文件#更新
我不明白我做错了什么。问题是PUT HTTP请求必须在配置文件路径上执行,而不是像您那样在编辑配置文件路径上执行。编辑配置文件路径与GET请求一起工作,并显示编辑配置文件表单。它实际上并没有更新配置文件 试一试
这很有效。但是另一个错误:Failure/error:specify{response.should_to(user_path(user))}预期的响应是重定向到的,但是是重定向到的,我认为这是Desive helpers的问题。