开发者

How submit data to a rails form via a URL?

I have a basic search form in my rails app that records each search that has been entered. I also want my users to be able to initiate a search with a url in the browser. E.g. http://www.example.com/searches?q=foo

I've played around with the different routing options and the logic in my controller but I can't seem to get this form:

<%= form_for(@search) do |f| %>
  <div class="field">
    <%= f.label :search %><br />
    <%= f.text_field :search %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

To initiate a POST action on the database and submit a new s开发者_如何学Cearch.

Thanks :)


Change your form to do a GET request instead of a POST then you can use both the form and the url:

<%= form_for(@search), :method => :get do |f| %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜