我正在使用带有rails的Ajax调用来调用控制器中的方法。我的问题是代码本身工作正常,我没有看到任何错误。当我去测试代码时,我得到了
ActionView::MissingTemplate: Missing template branch/call_s
ml], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "C:/home/Ruby/rails/showrooms/texting/app/views"
* "C:/home/Ruby/rails/showrooms/texting/app/views/shared"
* "C:/home/Ruby/rails/showrooms/texting/app/views"
这是我的控制器方法。
# Sends a SMS message to selected phone number.
#
def call_sms
if current_associate
@text_number = params[:phone_number]
@text_message = params[:text_message].to_s
if !@text_number.empty? && !@text_message.empty?
@sms = ShortMessagingService.new
if @sms.send(@text_number, @text_message)
@sms_message = "Status: #{@sms.sent?}"
end
else
@sms_message = 'Phone number and text field cannot be blank.'
end
else
@sms_message = 'You do not have perission for this feature.'
end
end
这是路线
# Small Messaging Service rout.
post 'call_sms' => 'branch#call_sms'
match 'call_sms' => 'branch#call_sms'
这是表格:
<%= form_for :call_sms, url: {action: "call_sms"},
:method => :post, :remote => true,
:html => {:id => 'sms_form'} do |f|
%>
.
.
.
<% end %>
这是我的测试
test "Can send sms messages." do
phone_number = '18006388875'
text_message = "Hey this is a test. Don't text and drive."
post :call_sms
assert_response :ok
end
答案 0 :(得分:1)
您的表单正在执行ajax请求,但您的测试用例不是。
代替post :call_sms
,试试这个:
xhr :post, :call_sms
这告诉测试用例发送ajax帖子而不是常规帖子。