In my code I have this :
def confirm
#pal = Pal.find(params[:palid])
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone
if #newuser.save
redirect_to(:controller => 'access', :action => 'index')
else
flash[:error] = "Retry."
render template: 'pals/new_password_asign'
end
end
private
def newuser_params
params.require(:newuser).permit(:username, :password_digest, :password_stored)
end
and after submitting my sign up form, I get redirected and the error "Retry" which I've specified.
Knowing that I create users and save them via rails console perfectly fine.
And this has got me thinking what would possibly prevent this from being saved?
What issues might occur during the saving?
======================================================
Rails v4
Ruby v2.02
I am using Bcrypt-ruby for authentication.
======================================================
Update #1
=======================================================
After adding the suggested solution of #mandeep, I now do get the error explanation, and in this explanation I get
" Password can't be blank "
Despite the fact that I do write the password before submiting
Check my sign up form
<%= form_for(:newuser, :url => {:action => 'confirm', :palid => #pal.id}) do |f| %>
<% if #newuser.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#newuser.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #newuser.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table summary="user form fields">
<tr>
<th><%= f.label(:username, "User Name") %></th>
<td><%= f.text_field :username, :value => #newuser.username, :class => "controls", :disabled => "true" %></td>
</tr>
<tr>
<th><%= f.label(:password, "password") %></th>
<td><%= f.password_field(:password) %></td>
</tr>
</table>
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
</div>
<% end %>
<% #newuser.password_stored = #newuser.password %>
</div>
</body>
==============================================
Update #2
Log and params after being request by #mandeep
Started GET "/pals" for 127.0.0.1 at 2014-07-03 16:15:44 +0000
ActiveRecord::SchemaMigration Load (0.1ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by palsController#index as HTML
pal Load (0.4ms) SELECT `pals`.* FROM `pals`
Rendered pals/index.html.erb within layouts/application (9.8ms)
Completed 200 OK in 280ms (Views: 260.9ms | ActiveRecord: 0.4ms)
Started GET "/pals" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Processing by palsController#index as HTML
pal Load (0.7ms) SELECT `pals`.* FROM `pals`
Rendered pals/index.html.erb within layouts/application (6.3ms)
Completed 200 OK in 103ms (Views: 101.4ms | ActiveRecord: 0.7ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/pals/new" for 127.0.0.1 at 2014-07-03 16:16:11 +0000
Processing by PalsController#new as HTML
Rendered pals/_form.html.erb (24.7ms)
Rendered pals/new.html.erb within layouts/application (43.6ms)
Completed 200 OK in 106ms (Views: 101.2ms | ActiveRecord: 1.6ms)
Started POST "/pals" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Processing by PalsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "pal"=>{"owner"=>"John", "title"=>"", "phone"=>"22", "price"=>"", "logtype"=>"", "description"=>"", "address"=>"", "latitude"=>"", "longitude"=>""}, "commit"=>"Create pal"}
(0.3ms) BEGIN
SQL (0.3ms) INSERT INTO `pals` (`address`, `created_at`, `description`, `logtype`, `owner`, `phone`, `title`, `updated_at`) VALUES ('', '2014-07-03 16:16:19', '', '', 'John', '22', '', '2014-07-03 16:16:19')
(56.6ms) COMMIT
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`username` = '22'
Redirected to http://localhost:3000/pals/confirm?palid=5
Completed 302 Found in 77ms (ActiveRecord: 58.1ms)
Started GET "/pals/confirm?palid=5" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Processing by PalsController#confirm as HTML
Parameters: {"palid"=>"5"}
pal Load (0.6ms) SELECT `pals`.* FROM `pals` WHERE `pals`.`id` = 5 LIMIT 1
Rendered pals/confirm.html.erb within layouts/application (6.4ms)
Completed 200 OK in 63ms (Views: 52.4ms | ActiveRecord: 0.8ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started POST "/pals/confirm?palid=5" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Processing by PalsController#confirm as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "newuser"=>{"password"=>"[FILTERED]"}, "commit"=>"Save Newuser", "palid"=>"5"}
pal Load (0.2ms) SELECT `pals`.* FROM `pals` WHERE `pals`.`id` = 5 LIMIT 1
(0.6ms) BEGIN
(0.1ms) COMMIT
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Rendered pals/confirm.html.erb within layouts/application (1.8ms)
Completed 200 OK in 60ms (Views: 50.6ms | ActiveRecord: 1.1ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
If you look at your code
def confirm
pal = Pal.find(params[:palid]) # you have find your pal and store it in "pal"
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone # you are using instance variable "#pal" which is not defined
# your other logic
end
Instead you should have your code like:
def confirm
#pal = Pal.find(params[:palid])
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone
# your other logic
end
Also in your form you should put this code
<% if #newuser.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#newuser.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #newuser.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
This will display if there are any validation errors in your form. For details refer to here
Update:
If you look at the parameters which are being passed from your form, notice this
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "newuser"=>{"password"=>"[FILTERED]"}, "commit"=>"Save Newuser", "palid"=>"5"}
There are couple of things wrong in your form:
a. Either you didn't enter your username in form or you haven't made your form properly because in params it's only showing password field "newuser"=>{"password"=>"[FILTERED]"}
b. You haven't permit your password field instead of permitting password you have permitted :password_digest, :password_stored. Your newuser_params should look like this:
def newuser_params
params.require(:newuser).permit(:username, :password)
end
c. what is "palid"=>"5" doing in your params? Is it a field in your form or what because it's not associated to newuser params
Check the validation errors in #newuser, namely #newuser.errors. There are methods that skip validations. Maybe you are using them in the console.
Related
I generate Model first
rails g model cat name
Then I genarate Scaffold Controller with the model name
rails g scaffold_controller zoo/cat name --model-name=zoo/cat
Then I add route
namespace :zoo do
resources :cats
end
Then I edit the Model
class Zoo::Cat < ActiveRecord::Base
end
The funny thing is it fails at first, with error
LoadError in Zoo::CatsController#index
Unable to autoload constant Cat, expected /home/minh/Desktop/fnl110/app/models/cat.rb to define it
def index
#zoo_cats = Zoo::Cat.all
end
Then I reload the page, it works without any error. Here is what server said:
Started GET "/zoo/cats" for 127.0.0.1 at 2016-01-10 21:05:30 +0700
ActiveRecord::SchemaMigration Load (0.1ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by Zoo::CatsController#index as HTML
Completed 500 Internal Server Error in 14ms (ActiveRecord: 0.0ms)
LoadError (Unable to autoload constant Cat, expected /home/minh/Desktop/fnl110/app/models/cat.rb to define it):
app/controllers/zoo/cats_controller.rb:7:in `index'
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.1ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.2ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (29.2ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.5ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.4ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.4ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (19.6ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.5ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (42.4ms)
Started GET "/zoo/cats" for 127.0.0.1 at 2016-01-10 21:10:15 +0700
Processing by Zoo::CatsController#index as HTML
Zoo::Cat Load (0.2ms) SELECT `cats`.* FROM `cats`
Rendered zoo/cats/index.html.erb within layouts/application (8.6ms)
Completed 200 OK in 200ms (Views: 197.5ms | ActiveRecord: 1.2ms)
Started GET "/assets/animal/bears.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/cats.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/dogs.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/scaffolds.self-d5c911709e0018272624ff2abf5748b5d0ff72c54f791bb9bcefd817c3322285.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/turbolinks.self-c37727e9bd6b2735da5c311aa83fead54ed0be6cc8bd9a65309e9c5abe2cbfff.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/jquery_ujs.self-d456baa54c1fa6be2ec3711f0a72ddf7a5b2f34a6b4f515f33767d6207b7d4b3.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/application.self-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/bears.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/jquery.self-a714331225dda820228db323939889f149aec0127aeb06255646b616ba1ca419.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/dogs.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/application.self-3b8dabdc891efe46b9a144b400ad69e37d7e5876bdc39dee783419a69d7ca819.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/cats.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
P/S: The reason of
rails g scaffold_controller zoo/cat name --model-name=zoo/cat
is
rails g scaffold_controller zoo/cat --model-name=zoo/cat
=> controller doesn't take model attributes
and
rails g scaffold_controller zoo/cat --model-name=cat
=> Error: undefined local variable or method `new_cat_path'
The error is normal, your model should be moved in the zoo directory, so app/models/zoo/cat.rb (instead of app/models/cat.rb). If you do that it will work immediately.
I might be wrong, but I believe the following happens:
When you load the page the first time, rails will lazily load the models, and will give you the error not because of the request, but because the file app/models/cat.rb should define Cat and not Zoo::Cat;
Even with the error, rails will have loaded the Zoo::Cat model, so when you reload the page, it won't encounter the error because the models have already been loaded, thus the request succeeds.
When I click 'log out' I can see that Rails processess the request, but I'm still logged in.
Any clue why this happens? Both locally and on Heroku.
Started DELETE "/users/sign_out" for IP at 2014-11-18 08:32:46 +0000
Processing by Devise::SessionsController#destroy as HTML
Parameters: {"authenticity_token"=>"TOKEN"}
Redirected to http://example.com/
Completed 302 Found in 14ms (ActiveRecord: 4.4ms)
Started GET "/" for 84.215.64.133 at 2014-11-18 08:32:47 +0000
Processing by StaticPagesController#blog as HTML
Rendered static_pages/blog.html.slim within layouts/application (0.7ms)
Completed 200 OK in 6ms (Views: 2.9ms | ActiveRecord: 1.6ms)
routes.rb
devise_for :users
From the log when editing a user:
Started PUT "/users" for 84.215.64.133 at 2014-11-18 14:40:30 +0000
Processing by Devise::RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QR/p3BAG+ocmacss5xDjuFDfhFSA+iv6VRK37uA9HcQ=", "user"=>{"mobile"=>"93441707", "email"=>"sss#
strosin.info", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Lagre"}
2014-11-18T14:40:31.095730+00:00 app[web.2]: App 131 stdout: Redirected to http://
The problem disapeared when I cleared the browser cache. (Using Chrome beta).
I want use angularjs in a rails project and I'm new to angularjs. for this, I create a staticpage controller with index action. I set this page for root page:
config/routes.rb
Restauranteur::Application.routes.draw do
root "staticpage#index"
end
now I download angular.js and add to asset pipeline. I remove turbolink and add below code to view/layouts/application.html.erb:
<!DOCTYPE html>
<html ng-app="restauranteur">
<head>
<title>Restauranteur</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div ng-view>
<%= yield %>
</div>
</body>
</html>
Then, I create HomeCtrl.js.coffee:
#restauranteur.controller 'HomeCtrl', ['$scope', ($scope) ->
# Notice how this controller body is empty
]
Now, I set an angular route for show default page, For this I create main.js.coffee and create a templates directory in public folder.
main.js.coffee:
#restauranteur = angular.module('restauranteur', [])
#restauranteur.config(['$routeProvider', ($routeProvider) ->
$routeProvider.
otherwise({
templateUrl: '../templates/home.html',
controller: 'HomeCtrl'
})
])
I create home.html in public/templates folder.
I want when I run the server,I see home.html, but the server run staticpage/index, where is the problem? Why home.html isn't set as root page and I cannot preview this?
server log:
Started GET "/" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Processing by StaticpageController#index as HTML
Rendered staticpage/index.html.erb within layouts/application (0.0ms)
Completed 200 OK in 12ms (Views: 11.0ms | ActiveRecord: 0.0ms)
Started GET "/assets/staticpage.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/restaurants.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/main.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/angular/controllers/HomeCtrl.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-17 18:54:31 +0430
Note: I use this tutorial for do this, but I am not successful.
There are two different layers of views involved in this example:
the Rails views
the ng-view of AngularJS
I think that 1) is actually working because you see that the application renders staticpage/index, just like you specified in the Rails routes.
To get 2) to work, you need to make sure that you include the main.js in the application.js using the require_tree . instruction you see in the tutorial you used.
After this is done, the Angular application will pick up the routes. It will detect that no route matches and executes the otherwise section. In your Rails log, you will see that it tries to request the view templates/home.html. Once this succeeds, the loaded view will be rendered client-side within the <div ng-view> element.
I want use angularjs in rails application and I'm new to angularjs. For this, I add angularjs file to project and created the below scripts and html:
HomeCtrl.js.coffee
#restauranteur.controller 'HomeCtrl', ['$scope', ($scope) ->
# Notice how this controller body is empty
]
RestaurantIndexCtrl.js.coffee:
#restauranteur.controller 'RestaurantIndexCtrl', ['$scope', '$location', '$http', ($scope, $location, $http) ->
$scope.restaurants = []
$http.get('./restaurants.json').success((data) ->
$scope.restaurants = data
)
]
main.js.coffee:
#restauranteur = angular.module('restauranteur', [])
#restauranteur.config(['$routeProvider', ($routeProvider) ->
$routeProvider.when('/restaurants', {
templateUrl: '../templates/restaurants/index.html',
controller: 'RestaurantIndexCtrl'
})
.otherwise({
templateUrl: '../templates/home.html',
controller: 'HomeCtrl'
})
])
I add below code to application.js:
//= require angular
//= require angular-mocks
//= require angular-route
//= require main
//= require HomeCtrl
//= require RestaurantIndexCtrl
and in application.html.erb:
<!DOCTYPE html>
<html ng-app="restauranteur">
<head>
<title>Restauranteur</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div ng-view>
<%= yield %>
</div>
</body>
</html>
and I created templates/home.html and templates/restaurants/index.html directories in public folder.
now I want render templates/home.html on localhost:3000 and render templates/restaurants/index.html on localhost:3000/restaurants. But I'm not successful and rails is rendered default page. I check my server log, every js and angularjs file are renderd, but when I go to localhost:3000/restaurants url, rails rendered default page of restaurants. (restaurants is a model that generated by sccafold.) How can I render angularjs html instead of rails html? Any idea?
server log:
Started GET "/restaurants" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Processing by RestaurantsController#index as HTML
Restaurant Load (0.0ms) SELECT "restaurants".* FROM "restaurants"
Rendered restaurants/index.html.erb within layouts/application (1.0ms)
Completed 200 OK in 12ms (Views: 11.0ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/restaurants.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/staticpage.css?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/main.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/angular/controllers/HomeCtrl.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/angular/controllers/RestaurantIndexCtrl.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-21 16:48:06 +0430
Note: For do this, I use this tutorial.
At first, if you want use routing, you must add this line in your app initialization:
#restauranteur = angular.module('restauranteur', ['ngRoute'])
And if you want url such as localhost:3000/restaurants, you must use html5-routing.
#restauranteur.config(['$locationProvider', '$urlRouterProvider',
function($locationProvider, $urlRouterProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
...
...
}
]);
Otherwise, just try localhost:3000/#/restaurants.
My app has a page allowing users to send me an email through a form (without my address being published). It's associated with an Email controller and is the #new action, which I rerouted to '/contact'.
The weird thing, is if the email doesn't send off for any reason (the user left a field blank or failed the math captcha I put in), when the controller renders "new" again, the url becomes '/emails'. I can't figure this one out at all. Some 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 make sure you answered the math question correctly."
render :new
else
if #email.save
Contact.contact_message(#email).deliver
flash[:success] = "Your email has sent! I'll try to get back to you shortly."
redirect_to root_path
else
flash.now[:error] = "Please correct the highlighted errors and try 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 was there before I added "as contact" in an attempt to fix it. Any ideas?
EDIT -- per garbage collection's request (sorry for the delay; haven't been near my computer for a bit), here's the dev log for navigating to /contact and submitting an unsuccessful email attempt (which refreshes and changes the URL to /emails):
Started GET "/contact" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Processing by EmailsController#new as 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".* FROM "users" WHERE "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 GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /application.css - 304 Not Modified (2ms)
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /custom.css - 304 Not Modified (2ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /angular.js - 304 Not Modified (0ms)
Started GET "/assets/pygments.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /pygments.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-transition.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-affix.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-alert.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-button.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-carousel.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-collapse.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-modal.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-dropdown.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-scrollspy.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-popover.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-tab.js - 304 Not Modified (46ms)
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-typeahead.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-tooltip.js - 304 Not Modified (0ms)
Started GET "/assets/emails.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /emails.js - 304 Not Modified (0ms)
Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /posts.js - 304 Not Modified (0ms)
Started GET "/assets/expand.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /expand.js - 304 Not Modified (0ms)
Started GET "/assets/sessions.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /sessions.js - 304 Not Modified (0ms)
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /users.js - 304 Not Modified (0ms)
Started GET "/assets/statics.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /statics.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /application.js - 304 Not Modified (0ms)
Started GET "/posts.json" for 127.0.0.1 at 2013-02-16 08:46:41 -1000
Processing by PostsController#index as JSON
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 2]]
[1m[35mPost Load (0.2ms)[0m SELECT "posts".* FROM "posts"
Completed 200 OK in 7ms (Views: 3.3ms | ActiveRecord: 0.4ms)
Started GET "/assets/sign_out.png" for 127.0.0.1 at 2013-02-16 08:46:41 -1000
Served asset /sign_out.png - 304 Not Modified (0ms)
Started POST "/emails" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Processing by EmailsController#create as 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".* FROM "users" WHERE "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 GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /application.css - 304 Not Modified (2ms)
Started GET "/assets/pygments.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /pygments.css - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-transition.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /angular.js - 304 Not Modified (0ms)
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /custom.css - 304 Not Modified (1ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-affix.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-button.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-alert.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-carousel.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-modal.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-collapse.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-dropdown.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-scrollspy.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-tooltip.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-tab.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-typeahead.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-popover.js - 304 Not Modified (0ms)
Started GET "/assets/expand.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /expand.js - 304 Not Modified (0ms)
Started GET "/assets/emails.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /emails.js - 304 Not Modified (0ms)
Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /posts.js - 304 Not Modified (0ms)
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /users.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /application.js - 304 Not Modified (1ms)
Started GET "/assets/sessions.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /sessions.js - 304 Not Modified (0ms)
Started GET "/assets/statics.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /statics.js - 304 Not Modified (0ms)
Started GET "/posts.json" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Processing by PostsController#index as JSON
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
[1m[36mPost Load (0.2ms)[0m [1mSELECT "posts".* FROM "posts" [0m
Completed 200 OK in 5ms (Views: 2.3ms | ActiveRecord: 0.3ms)
Started GET "/assets/sign_out.png" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /sign_out.png - 304 Not Modified (0ms)
It's expected to show '/emails' in the address bar since you just POST'ed to that url. If you really want to show '/contact', you should set up a route for POST like:
get '/contact', to: 'emails#new'
post '/contact', to: 'emails#create'
Maybe there's another, more concise way to do it, but this should work.