Answer the question
In order to leave comments, you need to log in
How to send a GET or POST request from a Rails controller file?
Hello. There is an application on rails and an SMS server, in the api of which it is written that in order to send SMS, you need to send a GET or POST request to the address " http://service.ru/sys/send.php?login=login&psw=paro
... " I have absolutely working code:
class OrdersController < ApplicationController
def mainp
end
def succsess
end
def list
@order = Order.all
end
def new
@order=Order.new
end
def create
@order = Order.new(order_params)
if @order.save
# GET or POST request here!
OrderMailer.new_call(@order).deliver
flash[:success] = "Спасибо!"
redirect_to succsess_path
else
#
end
end
def order_params
params.require(:order).permit(:name, :phone)
end
end
Answer the question
In order to leave comments, you need to log in
require 'uri' # подключение библиотеки для работы с адресами возможно в rails это не нужно
uri = URI.parse('http://сервис.ru/sys/send.php')
params = { login: 'login', password: '12345678' } # хэш с параметрами запроса
uri.query = URI.encode_www_form( params ) # кодирование параметров в строку запроса
require 'net/http' # подключение библиотеки для отправки HTTP запросов
Net::HTTP.get(uri) # собственно запрос
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question