【发布时间】:2013-04-20 08:05:49
【问题描述】:
我在不需要视图的表单控制器操作上遇到ActionView::MissingTemplate 错误,因为它将参数数据传递给控制器,然后控制器将发布 API 请求。
# Newsletter controller
def index
end
def subscribe
Gibbon.list_subscribe({:id => "my-list-id", :email_address => params[:email]})
end
在我的路线中:
# Routes
match "/subscribe", to: "newsletter#subscribe", :via => :post
查看我的表单所在的位置
# newsletter/index.html.erb
<%= form_tag subscribe_path, class: "form", remote: true do %>
<%= text_field_tag :email, nil, :class => 'email', :type=>"email", :placeholder => 'Sign up for newsletter' %>
<%= submit_tag "Go", class: "submit-button"%>
<% end %>
从通讯索引页面有一个表单,我想要它做的就是将用户电子邮件地址的请求发送到我的订阅操作
Error:
Started POST "/subscribe" for 127.0.0.1 at 2013-04-20 18:01:02 +1000
Processing by HomeController#subscribe as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZseTNfGI5151hk7fIhQH5/l536hc9/kdARf57352Y=", "email"=>"test-user@email.com", "commit"=>"Go"}
Completed 500 Internal Server Error in 1836ms
ActionView::MissingTemplate (Missing template home/subscribe, application/subscribe with {:locale=>[:en], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/Code/myapp/app/views"
):
以上是我收到的错误。我想知道如何假装这个模板问题,因为该操作不需要视图。
感谢您的帮助。
【问题讨论】:
-
在动作结束后尝试重定向
-
感谢 Zippie.. 看起来像这样工作。有没有办法让 redirect_to 和 flash 消息与远程表单一起使用?
-
远程表单?你的意思是AJAX表单?抱歉,如果我误解了某些内容,但您为什么需要远程表单和重定向?
标签: ruby-on-rails ruby-on-rails-3.2