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:
- 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
- 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
- all flash messages
:notice
. success should:success
, error should:alert
or:danger
depending on framework or convention using.
Comments
Post a Comment