1

我在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"
):

以上是我收到的错误。我想知道如何假装这个模板问题,因为该操作不需要视图。

谢谢你的帮助。

4

1 回答 1

1

你可以试试这个

def subscribe
  if request.post?
    Gibbon.list_subscribe({:id => "my-list-id", :email_address => params[:email]})
    redirect_to root_url, :notice => 'Success'
  else
    redirect_to some_place
  end
end

在您的路线中

post "/subscribe", to: "newsletter#subscribe"

检查您的路线以双重确认

于 2013-04-20T08:43:48.933 回答