javascript - Rails unable to render ajax flash message -


i'm seeing strange behavior in app. it's rails 4 app uses jquery. app's use of javascript pretty vanilla (i.e. no angular, react, ember stuff in mix).

on account settings page, there's form user can toggle value auto-renew subscription. when toggle, there's ajax call made subscriptions controller.

class subscriptionscontroller < applicationcontroller  def update   subscription_id = params['id']   updated_preference = params['auto-renew']   update = subscription.update_attributes(auto_renew: updated_preference)    respond_to |format|     if update       format.js { flash[:success] = "auto-renew information has been updated." }     else        format.js { flash[:error] = "something went wrong. please try again later." }       end   end end 

the desired behavior after update processed, flash message appears @ top of screen. set flash message in action above. inside template update action, scroll top of page.

# inside app/views/subscriptions/update.js.erb $('html, body').animate({ scrolltop: 0 }, 0)    

i'm seeing behavior (1) call subscriptions#update successful, (2) flash message appear , (3) when click link go account settings page, when page loads, flash message appears. refreshing same page doesn't anything, clicking link does.

i think part of issue may account settings managed different controller subscriptions , rails having trouble figuring out after renders template associated subscriptions#update action. honestly, i'm @ loss causing this.

can explain what's going on here? also, can tell me should desired behavior?

the flash not render in js, appears on next html page load. you'll need return success/error message ajax call , update html manually.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -