前提・実現したいこと
RubyonRailsでredirect_toが上手く動作しません。
Ajaxの通信を行って、特定の値を受信した場合のみ
redirect_toで tops/index.htmlの表示に飛ばしたいです。
ただし、今回はひとまずどのような値が来ても飛ばすように書いてあります。
以下のソースコードで何か問題がありますか?
また表示させるにはどうすればいいですか?
発生している問題・エラーメッセージ
以下のようにログが出るんですが、画面遷移せず、そのままです。
Started GET "/*****/************" for 127.0.0.1 at 2018-05-03 09:25:36 +0900 Processing by MatchesController#detail_areas_select as */* Parameters: {"store_id"=>"******.net"} User Load (1.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1 1 Redirected to http://localhost:3000/tops Completed 302 Found in 10ms (ActiveRecord: 1.6ms) Started GET "/tops" for 127.0.0.1 at 2018-05-03 09:25:36 +0900 Processing by TopsController#index as */* Rendering tops/index.html.erb within layouts/application User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1 Top Load (0.3ms) SELECT `tops`.* FROM `tops` Rendered tops/index.html.erb within layouts/application (9.8ms) Completed 200 OK in 178ms (Views: 136.9ms | ActiveRecord: 0.7ms)
該当のソースコード
MatchesController#detail_areas_select
def detail_areas_select if request.xhr? if params[:user_id] == current_user.email puts '1' else puts '2' end end redirect_to tops_path end
message.coffee (ajax部分)
received: (data) -> $.ajax( type: 'GET' url: '******' data: { user_id: data['message'] } ).done (data) -> $('#detail_areas_select').html(data)
試したこと
puts '1'とか'2'は通っているのにredirect_toだけ動作しません。
コントローラーの処理は https://qiita.com/ryo-ichikawa/items/57e447bca3404e5241ca を参考に行っております。
モーダル表示をクリックして、遷移させようとしています。これがいけないのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/03 01:04