javascript - Preserve error messages from validation in rails while redirecting to a new view? -


i checking errors using validates in modal. thats working fine , error messages shown(i used debugger confirm this). comes tricky part me.

so when validation failed doing in code:

  def create     checked_segment_topics = params[:checked_segment_topics].split(",")     @menu = menu.create_menu(checked_segment_topics, menuparams)     if @menu ==  true       redirect_to menus_path     else       redirect_to newmenu_path     end   end 

because doing redirect new view, error messages not shown. tried render , problem appends uuid form's id. because of javascript code fails. have find forms id few calculations before form submitted.

relevant parts of routes.rb file here:

get    '/menus'               => 'menus#index'    '/newmenu'             => 'menus#new' resources :menus,     only: [:new, :create, :edit, :update, :destroy] 

can guide me in right direction?

instance variables don't persist across requests. if don't want use session too, other way can think of store them in database without running validations.

def create   # logic build @menu    @menu.save(validate: false)    # logic redirection end 

and then, fetch them in required action , run validations on it.

def new   # logic fecth @menu    @menu.valid?    # logic render @menu end 

Comments