Forum: Ruby on Rails JS response -pls help somebody

E67b403d10e3525a29c15e64841f44f5?d=identicon&s=25 lekha p. (lekha_p)
on 2013-12-12 10:26
Hi all,
Pls help to find a solution :

i have a form like following
<%= form_for @product , :url => products_url(:format => 'js'), :html
=>{:id=>"create_product_form" ,:multipart => true,:remote=>true} do |f|
%>


what i have to do is like when submiting form i have to redirect to new
page else want to execute js like following

def create
if @product.save
redirect_to new_product_path
else
respond_to do |format|
    format.js
end
end


Here my issue i cant redirect_to new_products_path... what may be my
mistake ??  redirection is happening in console. but not not in ui.
whether it is because of ajax call in form, how to redirect ??







Thanks,
Lekha.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2013-12-12 12:31
(Received via mailing list)
On Thursday, December 12, 2013 9:26:14 AM UTC, Ruby-Forum.com User
wrote:
>
>
> Here my issue i cant redirect_to new_products_path... what may be my
> mistake ??  redirection is happening in console. but not not in ui.
> whether is is because ajax call in form, how to redirect ??
>
> It's because it's an ajax call - doing a redirect just affects what data
that ajax request returns (and it happens completely invisibly from the
point of view of the thing making the ajax request). It won't make the
containing page reload.
If you are rendering JS then a straightforward way is for your response
to
contain window.location = ...

Fred
B879c255691c4a2e8aa5e28a81f709e4?d=identicon&s=25 Manoj M. (manoj_m)
on 2013-12-13 10:04
Hi you can try


 respond_to do |format|
format.js { render :js =>
"window.location.replace('#{new_product_url}');" }
end


Thanks
Manoj Menon


lekha p. wrote in post #1130416:
> Hi all,
> Pls help to find a solution :
>
> i have a form like following
> <%= form_for @product , :url => products_url(:format => 'js'), :html
> =>{:id=>"create_product_form" ,:multipart => true,:remote=>true} do |f|
> %>
>
>
> what i have to do is like when submiting form i have to redirect to new
> page else want to execute js like following
>
> def create
> if @product.save
> redirect_to new_product_path
> else
> respond_to do |format|
>     format.js
> end
> end
>
>
> Here my issue i cant redirect_to new_products_path... what may be my
> mistake ??  redirection is happening in console. but not not in ui.
> whether it is because of ajax call in form, how to redirect ??
>
>
>
>
>
>
>
> Thanks,
> Lekha.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.