我在表單控制器操作上遇到ActionView::MissingTemplate
錯誤,因爲它將params數據傳遞給控制器,因此不需要視圖,但控制器會發布API請求。Rails 3表單的簡單自定義發佈操作
# 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"=>"[email protected]", "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 2013-04-20 08:34:24
感謝Zippie以後。它看起來像這樣的工作。有沒有辦法讓redirect_to和flash消息與遠程表單一起工作? – 2013-04-20 08:43:01
遠程表單?你的意思是AJAX表單?對不起,如果我誤解了一些東西,但爲什麼你需要一個遠程表單和重定向? – Zippie 2013-04-20 08:47:34