Reputation: 5644
I am getting this error:
Started POST "/submitEmailAddress" for 127.0.0.1 at 2015-03-13 15:29:26 +0100
Processing by OnepagerController#submitEmailAddress as JS
Parameters: {"utf8"=>"✓", "email"=>"[email protected]", "commit"=>"OK, LET'S GO!"}
submitEmailAddress
Completed 500 Internal Server Error in 12ms
ActionView::MissingTemplate (Missing template onepager/submitEmailAddress, application/submitEmailAddress with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/ola/.rvm/gems/ruby-2.2.0/gems/web-console-2.0.0/lib/action_dispatch/templates"
* "/Users/ola/Documents/RailsApps/newwp/app/views"
* "/Users/ola/.rvm/gems/ruby-2.2.0/gems/videojs_rails-4.6.1/app/views"
):
app/controllers/onepager_controller.rb:22:in `submitEmailAddress'
Rendered /Users/ola/.rvm/gems/ruby-2.2.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/missing_template.text.erb (0.3ms)
When I try to submit an email with this form:
(inside index.html.erb)
<div class="row">
<div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2">
<%= bootstrap_form_tag url: '/submitEmailAddress', remote: true, html: {class: 'emailForm'} do |f| %>
<%= f.email_field :email, hide_label: true %>
<%= f.submit "OK, LET'S GO!"%>
<% end %>
</div>
</div>
Here is my method:
(inside onepager_controller.rb)
def submitEmailAddress
puts "inside submitEmailAddress"
respond_to do |format|
format.html {redirect_to root_path}
format.js
end
end
And this is my routes:
(from my routes.rb)
root 'onepager#index'
post 'submitEmailAddress', to: 'onepager#submitEmailAddress'
Any idea of how I can fix this error?
Upvotes: 2
Views: 8452
Reputation: 167
Remove remote: true
in your form or createapp/views/onepager/submitEmailAddress.js.erb
Upvotes: 0
Reputation: 13344
You need to create a view template at either app/views/onepager/submitEmailAddress.js.erb
.
Since your controller has a redirect for the HTML format, you don't need the app/views/onepager/submitEmailAddress.html.erb
, but if you ever removed that redirect, or wanted to support browsers without JavaScript, you'd want the HTML template as well.
Upvotes: 2
Reputation: 3053
Your controller action has format.js
as a response, which should render app/views/onepager/submitEmailAddress.js.erb
. That template does not exist. You should either create it or have a different response.
The simplest response would be format.js { render nothing: true }
, but you need to decide what is appropriate.
Upvotes: 2