Thursday, 15 January 2015

ruby on rails - "New" render redirects to unexpected URL -



ruby on rails - "New" render redirects to unexpected URL -

my app has page allowing users send me email through form (without address beingness published). it's associated email controller , #new action, rerouted '/contact'.

the weird thing, if email doesn't send off reason (the user left field blank or failed math captcha set in), when controller renders "new" again, url becomes '/emails'. can't figure 1 out @ all. relevant code:

#emails_controller.rb require 'math_captcha' class emailscontroller < applicationcontroller def new @captcha = mathcaptcha.new @email = email.new end def create @captcha = mathcaptcha.decrypt(params[:captcha_secret]) @email = email.new(params[:email]) unless @captcha.correct?(params[:captcha]) || params[:captcha] == "21261" flash.now[:error] = "please create sure answered math question correctly." render :new else if @email.save contact.contact_message(@email).deliver flash[:success] = "your email has sent! i'll seek shortly." redirect_to root_path else flash.now[:error] = "please right highlighted errors , seek again." render :new end end end end

and:

#routes.rb resources :users, :posts, :sessions, :emails #... match '/contact', to: 'emails#new', as: 'contact'

the same problem there before added "as contact" in effort prepare it. ideas?

edit -- per garbage collection's request (sorry delay; haven't been near computer bit), here's dev log navigating /contact , submitting unsuccessful email effort (which refreshes , changes url /emails):

started "/contact" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 processing emailscontroller#new html rendered emails/new.html.erb within layouts/application (1.5ms) rendered layouts/_shim.html.erb (0.0ms) [1m[35muser load (0.1ms)[0m select "users".* "users" "users"."id" = ? limit 1 [["id", 2]] rendered layouts/_header.html.erb (2.0ms) completed 200 ok in 20ms (views: 19.5ms | activerecord: 0.1ms) started "/assets/application.css?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /application.css - 304 not modified (2ms) started "/assets/custom.css?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /custom.css - 304 not modified (2ms) started "/assets/jquery_ujs.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /jquery_ujs.js - 304 not modified (0ms) started "/assets/angular.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /angular.js - 304 not modified (0ms) started "/assets/pygments.css?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /pygments.css - 304 not modified (0ms) started "/assets/jquery.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /jquery.js - 304 not modified (0ms) started "/assets/bootstrap-transition.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-transition.js - 304 not modified (0ms) started "/assets/bootstrap-affix.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-affix.js - 304 not modified (0ms) started "/assets/bootstrap-alert.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-alert.js - 304 not modified (0ms) started "/assets/bootstrap-button.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-button.js - 304 not modified (0ms) started "/assets/bootstrap-carousel.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-carousel.js - 304 not modified (0ms) started "/assets/bootstrap-collapse.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-collapse.js - 304 not modified (0ms) started "/assets/bootstrap-modal.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-modal.js - 304 not modified (0ms) started "/assets/bootstrap-dropdown.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-dropdown.js - 304 not modified (0ms) started "/assets/bootstrap-scrollspy.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-scrollspy.js - 304 not modified (0ms) started "/assets/bootstrap-popover.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-popover.js - 304 not modified (0ms) started "/assets/bootstrap.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap.js - 304 not modified (0ms) started "/assets/bootstrap-tab.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-tab.js - 304 not modified (46ms) started "/assets/bootstrap-typeahead.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-typeahead.js - 304 not modified (0ms) started "/assets/bootstrap-tooltip.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /bootstrap-tooltip.js - 304 not modified (0ms) started "/assets/emails.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /emails.js - 304 not modified (0ms) started "/assets/posts.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /posts.js - 304 not modified (0ms) started "/assets/expand.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /expand.js - 304 not modified (0ms) started "/assets/sessions.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /sessions.js - 304 not modified (0ms) started "/assets/users.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /users.js - 304 not modified (0ms) started "/assets/statics.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /statics.js - 304 not modified (0ms) started "/assets/application.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:40 -1000 served asset /application.js - 304 not modified (0ms) started "/posts.json" 127.0.0.1 @ 2013-02-16 08:46:41 -1000 processing postscontroller#index json [1m[36muser load (0.1ms)[0m [1mselect "users".* "users" "users"."id" = ? limit 1[0m [["id", 2]] [1m[35mpost load (0.2ms)[0m select "posts".* "posts" completed 200 ok in 7ms (views: 3.3ms | activerecord: 0.4ms) started "/assets/sign_out.png" 127.0.0.1 @ 2013-02-16 08:46:41 -1000 served asset /sign_out.png - 304 not modified (0ms) started post "/emails" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 processing emailscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"hjd4q/tvu6ihqpdc7rpmks21s0gtiqilqoa8zklkxsk=", "email"=>{"name"=>"", "address"=>"", "subject"=>"", "content"=>""}, "captcha_secret"=>"xmukn1l8hvyplbsfymovwtieufyyo3qcxouuawh8vyw=\r\n", "captcha"=>"", "commit"=>"send"} rendered emails/new.html.erb within layouts/application (1.7ms) rendered layouts/_shim.html.erb (0.0ms) [1m[36muser load (0.1ms)[0m [1mselect "users".* "users" "users"."id" = ? limit 1[0m [["id", 2]] rendered layouts/_header.html.erb (2.5ms) completed 200 ok in 25ms (views: 22.0ms | activerecord: 0.1ms) started "/assets/application.css?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /application.css - 304 not modified (2ms) started "/assets/pygments.css?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /pygments.css - 304 not modified (0ms) started "/assets/bootstrap-transition.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-transition.js - 304 not modified (0ms) started "/assets/jquery_ujs.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /jquery_ujs.js - 304 not modified (0ms) started "/assets/angular.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /angular.js - 304 not modified (0ms) started "/assets/custom.css?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /custom.css - 304 not modified (1ms) started "/assets/jquery.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /jquery.js - 304 not modified (0ms) started "/assets/bootstrap-affix.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-affix.js - 304 not modified (0ms) started "/assets/bootstrap-button.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-button.js - 304 not modified (0ms) started "/assets/bootstrap-alert.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-alert.js - 304 not modified (0ms) started "/assets/bootstrap-carousel.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-carousel.js - 304 not modified (0ms) started "/assets/bootstrap-modal.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-modal.js - 304 not modified (0ms) started "/assets/bootstrap-collapse.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-collapse.js - 304 not modified (0ms) started "/assets/bootstrap-dropdown.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-dropdown.js - 304 not modified (0ms) started "/assets/bootstrap-scrollspy.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-scrollspy.js - 304 not modified (0ms) started "/assets/bootstrap-tooltip.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-tooltip.js - 304 not modified (0ms) started "/assets/bootstrap-tab.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-tab.js - 304 not modified (0ms) started "/assets/bootstrap-typeahead.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-typeahead.js - 304 not modified (0ms) started "/assets/bootstrap.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap.js - 304 not modified (0ms) started "/assets/bootstrap-popover.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /bootstrap-popover.js - 304 not modified (0ms) started "/assets/expand.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /expand.js - 304 not modified (0ms) started "/assets/emails.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /emails.js - 304 not modified (0ms) started "/assets/posts.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /posts.js - 304 not modified (0ms) started "/assets/users.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /users.js - 304 not modified (0ms) started "/assets/application.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /application.js - 304 not modified (1ms) started "/assets/sessions.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /sessions.js - 304 not modified (0ms) started "/assets/statics.js?body=1" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /statics.js - 304 not modified (0ms) started "/posts.json" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 processing postscontroller#index json [1m[35muser load (0.1ms)[0m select "users".* "users" "users"."id" = ? limit 1 [["id", 2]] [1m[36mpost load (0.2ms)[0m [1mselect "posts".* "posts" [0m completed 200 ok in 5ms (views: 2.3ms | activerecord: 0.3ms) started "/assets/sign_out.png" 127.0.0.1 @ 2013-02-16 08:46:44 -1000 served asset /sign_out.png - 304 not modified (0ms)

it's expected show '/emails' in address bar since post'ed url. if want show '/contact', should set route post like:

get '/contact', to: 'emails#new' post '/contact', to: 'emails#create'

maybe there's another, more concise way it, should work.

ruby-on-rails ruby-on-rails-3

No comments:

Post a Comment