igor-alexandrov / wiselinks

If Turbolinks are not enough for you. Wiselinks makes your application work faster.
MIT License
724 stars 89 forks source link

How to deal with RecordNotFound? #86

Open amnesia7 opened 10 years ago

amnesia7 commented 10 years ago

If a product in the catalog is not found (ie its listed and then after the page has loaded for the user the product gets removed for whatever reason) I redirect the user to the root_path using redirect_to root_path but since my homepage isn't a wiselinks-enabled it goes a bit wrong when I try to aply wiselinks to this process because it tries to load the root_path html in my #product_list container.

I've seen #57 and tried using the following:

if request.wiselinks?
  render js: "<script>window.location.href = '#{root_path}'</script>"
else
  redirect_to root_path
end

but this just makes a large chunk of the page disappear (that would normally be replaced by wiselinks with the next page's content)...and then it redirects the browser to the root_path.

Is there a way to make wiselinks not remove the content before doing the redirect?

Alternatively, is there a way to leave the page content alone and just show my flash message ("Product not found")?

Is there a better/another way to deal with RecordNotFound?

Thanks