我是ruby on rails的新手.我正在尝试使用Rails,ActiveResource类来使用我现有的Java REST api,但每次资源URL命中时都是错误的(https://myapp/resource/**apis**/responce.json),其中正确的url是(https://myapp/resource/**api**/responce.json)
问题是活动资源映射apis /而不是api /
下面是我的model => app/model/api.rb的代码
class Api < ActiveResource::Base
self.site = "https://myapp/resource"
self.format = :json
self.element_name = "api"
end
Run Code Online (Sandbox Code Playgroud)
app/controllers/api_controller.rb中的代码
@api = Api.get(:responce, :key => "key", :userId =>'1')
Run Code Online (Sandbox Code Playgroud)
上面的代码总是给出404错误,当我检查日志时,资源正在命中https://myapp/resource/**apis**/responce.json?key=key&userId=1
它必须命中资源URL的位置https://myapp/resource/**api**/responce.json
有人可以帮助选择帮手,因为我是Ruby On rails的新手.
我有一个json对象如下,
@response = {"status" => "200", "fruit" => [ {
"id" => 1,
"name" => "Apple"
}, {
"id" => 2,
"name" => "Mango"
} ]
}
Run Code Online (Sandbox Code Playgroud)
在帮助器中我返回值"return @response ['rateCard']"现在我想从这个帮助器在视图文件中生成这样的代码所以它将有选择框像
<select name='fruit'>
<option value="1">apple</option>
<option value="2" selected>mango</option>
</select>
Run Code Online (Sandbox Code Playgroud)
实际上我有一个帮助者"Fruits_helper.rb"正在返回
def selFruit
@resp = Fruit.getFruit # this will return @response object as mentioned above
return @resp['fruit']
end
Run Code Online (Sandbox Code Playgroud)
================================================== ================================所以在我的fruit.html.erb文件中我有一小段代码如下
<%= form_for(:AdminLogin) do |f| %>
<div>
<%= select_tag "fruit", options_for_select(selFruit.each{|fruit,key| [fruit[key]=>'name',fruit[key]=>'id']}) %>
<div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
================================================== ==========================上面的代码给了我o/p …