2
我正在使用Rails 4.我現在用的是Mailgun寶石允許用戶通過電子郵件發送書籤,應用社交書籤項目,保存爲書籤記錄。我的方法在本地控制檯工作,但通過發送電子郵件至Heroku的測試時,我收到此:::的ActionView時MissingTemplate - 軌道4
2014-10-29T15:11:10.881903+00:00 app[web.1]: Completed 500 Internal Server Error in 1086ms
2014-10-29T15:11:10.881913+00:00 app[web.1]: Completed 500 Internal Server Error in 1086ms
2014-10-29T15:11:10.884245+00:00 app[web.1]:
2014-10-29T15:11:10.884248+00:00 app[web.1]: ActionView::MissingTemplate (Missing template bookmarks/create_by_mail, application/create_by_mail with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
2014-10-29T15:11:10.884249+00:00 app[web.1]: * "/app/app/views"
2014-10-29T15:11:10.884251+00:00 app[web.1]: * "/app/vendor/bundle/ruby/2.0.0/gems/devise-3.4.0/app/views"
2014-10-29T15:11:10.884252+00:00 app[web.1]:):
爲什麼會尋找一個看法?這一行動應該在幕後完全處理。
相關代碼:
skip_before_filter :verify_authenticity_token, only: [:create_by_mail]
def create_by_mail
@sender = params["sender"]
@subject = params["subject"]
@body = params["body-plain"]
@bookmark = Bookmark.new(title: get_title_from_link(@subject), link: @subject, description: @body, category_ids: category_matcher(@body))
@bookmark.save!
end
私有方法:
private
require 'net/http'
require 'nokogiri'
require 'open-uri'
def get_base(url)
uri = URI(url)
response = Net::HTTP.get_response(uri)
base = response["location"]
if base
base
else
url
end
end
def get_title_from_link(url)
base_url = get_base(url)
doc = Nokogiri::HTML(open(base_url).read)
doc.at_css("title").text
end
def parse_categories(text)
r = /#.[^\s]+/
text.scan(r)
end
def category_matcher(text)
category_array = []
parse_categories(text).each do |cat|
category_array << Category.find_or_create_by(name: cat).id
end
category_array
end
def categories_to_array(categories)
category_array = []
categories.each do |key, value|
if value == '"id"=>"1"'
category_array << key
end
end
category_array
end