我正在尝试使用faraday从我的控制器向第三方网站发出发帖请求,但无法正常工作吗?
我的房屋控制器中有一个方法可以发出请求,为该方法设置路由并为我的请求提供表格,但是我不知道我在做什么错,我无法获得成功的请求
#homes_controller.rb
def alpaca
@conn = Faraday.post('https://paper-api.alpaca.markets/v2/orders') do |req|
req.headers['APCA-API-KEY-ID'] = 'key'
req.headers['APCA-API-SECRET-KEY'] = 'secret'
req.body = "{'symbol': '#{params[:ticker]}'}"
req.body = "{'qty': '#{params[:qty]}'}"
req.body = "{'side': '#{params[:side]}'}"
req.body = "{'type': '#{params[:ticker]}'}"
req.body = "{'time_in_force': '#{params[:time_in_force]}'}"
end
redirect_to homes_path
end
#routes.rb
resources :homes
root 'homes#index'
post '/alpaca', to: 'homes#alpaca'
#homes/index.html.rb
<%=form_tag alpaca_path do %>
<%=label_tag "Ticker"%>
<%=text_field_tag :ticker %>
<%=label_tag "qty"%>
<%=number_field_tag :qty %>
<%=label_tag "side"%>
<%=text_field_tag :side %>
<%=label_tag "type"%>
<%=text_field_tag :type %>
<%=label_tag "time_in_force"%>
<%=text_field_tag :time_in_force %>
<%=submit_tag%>
<%end%>
我正在尝试获取此表格,以发布传递给羊驼的贸易API的参数