我在 javascript homepage.js 文件中发送 ajax 请求
function GotoHomePage() {
var URL = 'homepage/1';
$.ajax({
url : URL,
success : function() {
},
error:function(){
}
});
}
控制器代码 products_controller.rb 文件:
def homepage
@val="here is query"
end
路线 routes.rb 文件:
match "homepage/1" => 'products#homepage'
Rspec products_controller_spec.rb 文件:
describe ProductDetailsController do
render_views
describe '#homepage' do
before { xhr :get, 'homepage/1' }
it { response.status.should == 200 }
end
end
但我收到错误
before { xhr :get, 'homepage/1' }
ActionController::RoutingError:
No route matches {:controller=>"products", :action=>"homepage/1"}