Ruby/Rails - 将参数插入位于控制器中的查询字符串中
我的视图中有一个 link_to ,它将指向在控制器中动态创建的 URL(查询字符串)。
<%= link_to "Search Venue", @venue_search, :target => :blank %>
在控制器中,我从模型中提取一些属性,并在查询中使用这些值来访问雅虎的 API,
@event = Event.find(params[:id])
search_values = {
:api_key => 'xxxxxxxxx',
:search_text => @event.venue_name,
:location => @event.venue_zipcode,
:radius => 100
}
@venue_search = "http://yahooapis.com/rest/?method=venue.search&" + search_values.to_query
到目前为止,一切都运行良好。
我想在查询中手动输入更多参数,我只是想知道最好的方向是什么。
有没有办法创建一个表单,其中有一些文本字段,我可以使用这些文本字段将参数手动插入到查询字符串中,并使用提交按钮将 url 作为 link_to 调用?
我在想类似的事情
<% form_for @venue_search(:city, :state) do |f| %>
<%= f.text_field :city %>
<%= f.text_field :state %>
<% end %>
以及如何将这两个新参数添加到查询中然后执行查询
这可能吗?
I have a link_to in my view which is going to a URL( query string) that is created dynamically in the controller.
<%= link_to "Search Venue", @venue_search, :target => :blank %>
and in the controller I'm pulling some attributes from a model and using those values in a query to hit Yahoo's API and
@event = Event.find(params[:id])
search_values = {
:api_key => 'xxxxxxxxx',
:search_text => @event.venue_name,
:location => @event.venue_zipcode,
:radius => 100
}
@venue_search = "http://yahooapis.com/rest/?method=venue.search&" + search_values.to_query
And everything is working perfect so far.
I would like to manually enter a few more parameters into the query and I'm just wondering what would be the best direction to go.
Is there a way to create a form which some text fields that I can use to insert parameters manually into the query string and to use the submit button to call the url as a link_to?
I was thinking something like
<% form_for @venue_search(:city, :state) do |f| %>
<%= f.text_field :city %>
<%= f.text_field :state %>
<% end %>
And some how add those two new parameters to the query and then execute the query
Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的问题,您可以用于发送“GET”请求 - 在这种情况下参数将被放置在查询中:
希望它对您有帮助。
If i properly understand your question, you can use for sending 'GET' request - in such case parameters will be placed in query:
Hope its help you.