How do I make this AJAX request hit the right URL for its respective controller action?
I have this AJAX request inside some jquery code that enables autocomplete:
$.ajax({type:"POST", url:("/showable_videos/create.js"), data:{video:{profile:val}}});
This field that has autocomplete is in the video show view. I get this error from the request:
Started PUT "/showable_video/create.js" for 127.0.0.1 at Tue Apr 26 00:46:37 -0700 2011
ActionController::RoutingError (No route matches "/showable_videos/create.js"):
I'm trying to hit the create method in my showable_obj开发者_运维技巧ects controller:
def create
@video = Video.find(params[:id])
@showable_video = current_user.showable_videos.create(:video => @video, :profile => @profile)
respond_to do |format|
format.html
format.js
end
end
Please let me know if you'd like to see more code.
Create method is only accessible through post queries directly to the controller by default. So you should be accessing the url /showable_videos.js
instead.
this works:
$.ajax({type:"POST", url:("/showable_videos"), data:{video:{profile:val}}});
$.ajax({type:"POST", url:("/showable_videos"), data:{video:{profile:val}}}); this will works
精彩评论