Rails: redirecting to wrong path -


@trip = trip.new(trip_par)    if @trip.save     redirect_to trips_index_path     flash[:notice] = "success"   else     render trips_new_path     flash[:notice] = "error"   end 

when i'm sending 'form' trips/new got 'success' flash , sends me 'trips/index'path view 'trips/show'. tried several combinations , still same. routes:

get 'trips/show', to: 'trips#show' 'trips/new'  'trips/edit'  'trips/delete'  'trips/index', to: 'trips#index' 

may problem routing/action controllers or mistake?

few remarks:

  1. your routes.rb looks incorrect (not solving point, save time after): get 'trips/delete' should not get delete.

to make easier recommend replacing 5 lines of current routes.rb single 1 job: resources :trips

all routing tips can found here

  1. try placing flash calls before redirect_to
if @trip.save     flash[:notice] = "success"     redirect_to trips_index_path else     flash[:notice] = "error"     render trips_new_path end 
  1. all flash messages :notice. success should :success , error should :alert or :danger depending on framework or convention using.

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -