나는이처럼 보이는 컨트롤러 방법에 대한 'POST'를 요청하기 위해 노력하고있어 :내 'POST'요청이 내 방법을 보내지 않는 이유는 무엇인가요?
$.ajax({type: "POST", url: something, data: {to_find_id: 978636122}, success:function(){ }});
은 다음 로그 보여줍니다 내 데이터, 전송 :
Started POST "/thingys/519716477/do_something" for 127.0.0.1 at 2014-04-03 14:54:44 +0200
Processing by ThingysController#do_something as */*
Parameters: {"to_find_id"=>"978636122", "thingy_id"=>"519716477"}
←[1m←[36mUser Load (0.0ms)←[0m ←[1mSELECT "users".* FROM "users" WHERE "users"."id" =? LIMIT 1←[0m [["id", 702273327]]
Redirected to http://localhost:3000/
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
의 간단한 설명을 302 Found
: WIKIPEDIA-LINK
내 방법 :
def do_something
Something.create(timespan_id: params[:to_find_id].to_s, thingy_id: @thingy.id)
respond_to do |format|
format.js {render :nothting => true}
end
end
내 routes.rb
- 파일에 내 방법을 이미 정의했습니다.
resources :thingys do
post 'do_something'
post 'undo_something'
end
그래서 요청을 보내고 심지어 방법을 찾습니다.
내가 그것을 어떻게 작동시킬 수 있는지 알고 있니?
편집 :
내 정품 토큰 추가했습니다,하지만 난 여전히 내 방법에 액세스 할 수 없습니다.
Here is what I get now:
Started POST "/thingys/519716477/add_something?&authenticity_token=1l3tTWfwNgt56lp93w2QghUJvUYZn87V/8Zs7Fcrijq+8=" for 127.0.0.1 at 2014-04-07 13:04:15 +0200
Processing by ThingysController#add_something as */*
Parameters: {"to_find_id"=>"310026847", "authenticity_token"=>"1l3tTWfwNgt56lp93w2QghUJvUYZn87V/8Zs7Fcrijq 8=", "subgroup_id"=>"519716477"}
←[1m←[35mUser Load (0.5ms)←[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 702273327]]
←[1m←[36mThingyp Load (0.5ms)←[0m ←[1mSELECT "subgroups".* FROM "thingys" WHERE "thingys"."id" = ? LIMIT 1←[0m [["id", "519716477"]]
Redirected to http://localhost:3000/
Completed 302 Found in 22ms (ActiveRecord: 1.0ms)
나는 또한 나의 ThingysController 내와 ApplicationController에
protect_from_forgery with: :exception
및
skip_before_filter:verify_authenticity_token
을 추가했습니다.
에 무엇을 작동하지 않는 이유는 무엇입니까? 너는 무엇을 기대 하느냐? 대신 무엇이 발생합니까? –