我有@vote的远程表单,它提交了一个选择ID。我只想在成功的创建操作后呈现部分而不是重定向。 操作成功,创建了投票,未达到我的create.js.erb并且它给出了RoutingError。服务器窗口看起来像处理html格式。任何帮助表示赞赏!
形式:
= form_for Vote.new, url: poll_votes_path(@model), remote: true do |f|
%ul
- choices.each do |choice|
%li
%label
= radio_button_tag 'choice', choice.id, false, required: true
= choice.body
.submit
= f.submit "Stemmen", class: "send-vote", id: "poll_#{@model.id}"
控制器:
def create
@poll = Poll.find(params[:poll_id])
vote = Vote.new(poll: @poll, choice_id: params[:choice], ip: request.remote_ip, email: params[:email])
if vote.save
# cookies["#{@poll.id.to_s.crypt('lenniskink')}"] = {value: params[:choice], expires: 1.year.from_now}
end
respond_to do |format|
format.js
end
end
路线:
resources :polls, path: 'peilingen' do
member do
get :results
put :sort
end
resources :votes, path: 'stemmen', only: [:create, :index]
end
create.js
浏览器:
ActionController::RoutingError at /peilingen/581/stemmen
Not Found
服务器:
Started POST "/peilingen/581/stemmen" for ::1 at 2017-02-18 14:08:53 +0100
Processing by Admin::VotesController#create as HTML
Parameters: {"utf8"=>"✓", "choice"=>"2711", "commit"=>"Stemmen", "poll_id"=>"581"}
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 461 ORDER BY login ASC LIMIT 1
(0.3ms) BEGIN
SQL (2.0ms) UPDATE `users` SET `last_request_at` = '2017-02-18 13:08:53', `perishable_token` = 'ouUIlXRADq3WTnrysQGC', `updated_at` = '2017-02-18 13:08:53' WHERE `users`.`id` = 461
(1.0ms) COMMIT
Organization Load (0.6ms) SELECT `organizations`.* FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.`id` = `organizations_users`.`organization_id` WHERE `organizations_users`.`user_id
` = 461
User Store (29.8ms) {"id":461}
Poll Load (0.6ms) SELECT `polls`.* FROM `polls` WHERE `polls`.`id` = 581 LIMIT 1
(1.0ms) BEGIN
Choice Load (0.5ms) SELECT `choices`.* FROM `choices` WHERE `choices`.`id` = 2711 LIMIT 1
SQL (24.5ms) INSERT INTO `votes` (`poll_id`, `choice_id`, `ip`, `created_at`) VALUES (581, 2711, '::1', '2017-02-18 13:08:53')
SQL (0.8ms) UPDATE `choices` SET `votes_count` = COALESCE(`votes_count`, 0) + 1 WHERE `choices`.`id` = 2711
(0.8ms) SELECT COUNT(*) FROM `votes` WHERE `votes`.`poll_id` = 581
SQL (2.7ms) UPDATE `polls` SET `votes_count` = 157, `updated_at` = '2017-02-18 13:08:53' WHERE `polls`.`id` = 581
(1.6ms) COMMIT
Completed 404 Not Found in 139ms (Searchkick: 29.8ms | ActiveRecord: 37.1ms)
ActionController::RoutingError - Not Found:
app/controllers/application_controller.rb:26:in `not_found'
路线:
results_poll GET /peilingen/:id/results(.:format) admin/polls#results
sort_poll PUT /peilingen/:id/sort(.:format) admin/polls#sort
poll_votes GET /peilingen/:poll_id/stemmen(.:format) admin/votes#index
POST /peilingen/:poll_id/stemmen(.:format) admin/votes#create
polls GET /peilingen(.:format) admin/polls#index
POST /peilingen(.:format) admin/polls#create
new_poll GET /peilingen/new(.:format) admin/polls#new
edit_poll GET /peilingen/:id/edit(.:format) admin/polls#edit
poll GET /peilingen/:id(.:format) admin/polls#show
PATCH /peilingen/:id(.:format) admin/polls#update
PUT /peilingen/:id(.:format) admin/polls#update
DELETE /peilingen/:id(.:format) admin/polls#destroy