I call redirect_to in this def create:
class M::TodosController < ApplicationController
layout 'm/application'
def create
@todo = @goal.todos.build(params[:todo])
...
puts "XXXXX => " + m_goal_todo_path(@goal, @todo)
redirect_to m_goal_todo_path(@goal, @todo)
end
...
I check routes => rake routes:
m_goal_todo GET /m/goals/:goal_id/todos/:id(.:format) m/todos#show
In my log:
XXXXX => /m/goals/46/todos/358
Started POST "/m/goals/46/todos" for 127.0.0.1 at 2014-03-13 13:47:14 +0900
Processing by M::TodosController#create as */*
Parameters: {"todo"=>{"content"=>"23"}, "goal_id"=>"46"}
SQL (0.4ms) DELETE FROM "authentication_tokens" WHERE (logged_in_until < '2014-03-13 13:47:14.014105')
AuthenticationToken Load (0.5ms) SELECT "authentication_tokens".* FROM "authentication_tokens" WHERE "authentication_tokens"."token" = '5aTg7cWiDXAJj8IHd2NePqat1fNaXc0Nu9kAtS2PF6N8TDR8T5IeZYUZsT4Iy7dkuyy5FkmO_qyDuXX8' LIMIT 1
...
& still It doesn't redirect to -> /m/goals/46/todos/358 it goest to /m/goals/46/
I'm using Rails 3.2.13 & jQueryMobile
+++ UPDATE +++
Tried
def create
@todo = @goal.todos.build(params[:todo])
...
puts "XXXXX => " + m_goal_todo_path(@goal, @todo)
respond_to do |format|
format.html { redirect_to m_goal_todo_path(@goal, @todo)}
end
end
Getting the same behavior.
Also, I tried disabling Ajax by adding rel="external", nothings changes
<a href="#" class="add center" data-role="button" data-rel="back" data-mini="true" data-inline="true" rel="external">やるべきことを追加</a>
+++ UPDATE 2 +++
new.html.erb
<div class="center">
<a href="#" class="add center" data-role="button" data-rel="back" data-mini=" true" data-inline="true" data-ajax="false">やるべきことを追加</a>
</div>
and javascript
$(document).on('click', '.todos_new_page .add', function() {
var $this = $(this);
var goalId = $this.closest('.todos_new_page').data('goal-id');
var $content = $this.closest('[data-role=content]').find('#content');
if ( $content.val() == "") {
alert("記入して下さい");
return false;
}
var content = $content.val();
$.ajax({
url: '/m/goals/' + goalId + '/todos',
type: 'POST',
data: {todo: {content: content}},
error: defaultAjaxError
});
});
In Jquery mobile views are not changing as it is totally Ajax based. you need to specify something like this
def create
@todo = @goal.todos.build(params[:todo])
...
puts "XXXXX => " + m_goal_todo_path(@goal, @todo)
respond_to do |format|
format.html { redirect_to m_goal_todo_path(@goal, @todo)}
end
end
Or you need to disable Ajax for form from where create action is called using data-ajax = "false"
cuz I have this peace of code -> data-rel="back"
I was redirected to /m/goals/46/todos/358
So, I deleted it :) & add ⬇ to my ajax call
success: function(link) {
$.mobile.changePage('/m/'+link.go);
}
Where link.go -> render "/m/goals/_update_goal_html", json: { go: "/goals/" + @goal.id.to_s + "/todos/" + @todo.id.to_s}
Works fine :)
Babasaheb Gosavi, thank you for your help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.