I have presently a render :json which modify the current page if @request.save format.html { redirect_to(@request) } format.json { render :json => { :result => ''success'', :request => request_path(@request) } } .... but I would like rather to redirect to an index page I wrote this but it doesn''t redirect ... format.json { redirect_to requests_url } what should I write to redirect correctly to an html page ? thanks for your help erwin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Here is an example: format.json { render :json => { :redirect => requests_url } } and then on your client redirect like this: if (json.redirect) { window.location = json.redirect; } Also try http://www.google.com/search?q=json+redirect Does this solve your problem? /Lasse 2010/3/23 Erwin <yves_dufour-ee4meeAH724@public.gmane.org>> I have presently a render :json which modify the current page > > if @request.save > format.html { redirect_to(@request) } > format.json { render :json => { :result => ''success'', :request > => request_path(@request) } } > .... > > but I would like rather to redirect to an index page > I wrote this but it doesn''t redirect ... > > format.json { redirect_to requests_url } > > what should I write to redirect correctly to an html page ? > > thanks for your help > > erwin > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lasse Bunk wrote:> Here is an example: > > format.json { render :json => { :redirect => requests_url } } > > and then on your client redirect like this: > > if (json.redirect) { > window.location = json.redirect; > } > > Also try http://www.google.com/search?q=json+redirect > > Does this solve your problem? > > /Lasse > > 2010/3/23 Erwin <yves_dufour-ee4meeAH724@public.gmane.org>thanks for your help it seems that json.redirect is bypassed... I put an alert, and it''s not fired up if (json.redirect) { alert(''redirect''); } -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
in my controller the create action is : respond_to do |format| if @request.save flash[:notice] = ''Request was successfully created.'' format.html { redirect_to requests_url } format.xml { render :xml => @request, :status => :created, :location => @request } format.json { render :json => {:result => ''success'', :redirect => requests_url } } format.js else ..... once the request is saved, ... I get in the log Completed in 563ms (View: 1, DB: 5) | 200 OK [http://localhost/requests] I should have 200 OK [http://localhost:3000/requests] -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe you''re not requesting it properly, making sure that you call the format.json part? It seems it redirects to requests_url in format.html. /Lasse 2010/3/23 Kad Kerforn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> in my controller the create action is : > > respond_to do |format| > if @request.save > flash[:notice] = ''Request was successfully created.'' > format.html { redirect_to requests_url } > format.xml { render :xml => @request, :status => :created, > :location => @request } > format.json { render :json => {:result => ''success'', :redirect > => requests_url } } > format.js > else > ..... > > once the request is saved, ... I get in the log > > Completed in 563ms (View: 1, DB: 5) | 200 OK [http://localhost/requests] > > I should have > 200 OK [http://localhost:3000/requests] > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Just to clarify: A proper json request is to call /path.json or call /path (with or without .json) with an "Accept: application/json" header. /Lasse 2010/3/24 Lasse Bunk <lassebunk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Maybe you''re not requesting it properly, making sure that you call the > format.json part? It seems it redirects to requests_url in format.html. > > /Lasse > > 2010/3/23 Kad Kerforn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > in my controller the create action is : >> >> respond_to do |format| >> if @request.save >> flash[:notice] = ''Request was successfully created.'' >> format.html { redirect_to requests_url } >> format.xml { render :xml => @request, :status => :created, >> :location => @request } >> format.json { render :json => {:result => ''success'', :redirect >> => requests_url } } >> format.js >> else >> ..... >> >> once the request is saved, ... I get in the log >> >> Completed in 563ms (View: 1, DB: 5) | 200 OK [http://localhost/requests] >> >> I should have >> 200 OK [http://localhost:3000/requests] >> -- >> Posted via http://www.ruby-forum.com/. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lasse Bunk wrote:> Maybe you''re not requesting it properly, making sure that you call the > format.json part? It seems it redirects to requests_url in format.html. > > /Lasse > > 2010/3/23 Kad Kerforn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>yes... after some tests, I rewrote the original format.json line (from the plugin uploadify_rails) as : format.json { render :json => { :result => ''success'', :request => member_request_url(@request[:id]) } } this redirects to :show (don''t misunderstand it , ''request'' is my model instance...) and I just modified the :show action as following : respond_to do |format| .. format.js { render :update do |page| page.redirect_to member_requests_url end } end this time, the redirection is fine.... which is enough for my test, I''ll try to investigate a little bit more to understand why: format.json { render :json => { :result => ''success'', :request => member_request_url(@request[:id]) } } redirects to :show with a format .js I thought I could write a :callback => ''index'', no change... it''s always redirected to :show... OR is it an issue in using :request => maybe this is a parameter used by the render.json ... thanks a lot for your help -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Again: Make sure that format.json is in fact called. Maybe try removing format.html to make sure that the redirect isn''t done there. /Lasse 2010/3/25 Kad Kerforn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> Lasse Bunk wrote: > > Maybe you''re not requesting it properly, making sure that you call the > > format.json part? It seems it redirects to requests_url in format.html. > > > > /Lasse > > > > 2010/3/23 Kad Kerforn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > yes... after some tests, I rewrote the original format.json line (from > the plugin uploadify_rails) as : > > format.json { render :json => { :result => ''success'', :request > => member_request_url(@request[:id]) } } > > this redirects to :show (don''t misunderstand it , ''request'' is my > model instance...) > and I just modified the :show action as following : > > respond_to do |format| > .. > format.js { > render :update do |page| > page.redirect_to member_requests_url > end > } > end > > this time, the redirection is fine.... which is enough for my test, > I''ll try to investigate a little bit more to understand why: > > format.json { render :json => { :result => ''success'', :request > => member_request_url(@request[:id]) } } > > redirects to :show with a format .js > > I thought I could write a :callback => ''index'', no change... it''s always > redirected to :show... > OR is it an issue in using :request => > maybe this is a parameter used by the render.json ... > > thanks a lot for your help > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.