Я использую вызов 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
Ваша форма выполняет запрос ajax, но ваш тестовый пример отсутствует.
Вместо post :call_sms
, попробуйте следующее:
xhr :post, :call_sms
Это говорит, что тестовый пример отправляет сообщение ajax вместо обычной почты.
render :nothing => true
он не загружает call_sms.js.erb, и я получаю сообщение об ошибке в своей консоли