Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 重定向到给定表单提交的页面_Html_Ruby On Rails_Forms - Fatal编程技术网

Html 重定向到给定表单提交的页面

Html 重定向到给定表单提交的页面,html,ruby-on-rails,forms,Html,Ruby On Rails,Forms,我在/parties上显示了下面的一个表单,我想获取用户在此表单中输入的任何内容,并将其添加到url。也就是说,如果他们搜索“hello”,他们将被重定向到parties/hello <h1>Search for a Party</h1><br> <%= form_tag({:action => "search"}, {:method => "get"}) do %> <%= label_tag :

我在/parties上显示了下面的一个表单,我想获取用户在此表单中输入的任何内容,并将其添加到url。也就是说,如果他们搜索“hello”,他们将被重定向到parties/hello

    <h1>Search for a Party</h1><br>
    <%= form_tag({:action => "search"}, {:method => "get"}) do %>
        <%= label_tag :q, "Enter Playlist Code:" %>
        <%= text_field_tag(:q) %>
        <%= submit_tag("Find Playlist", :name => "submit") %>
    <% end %>
搜索参与方
“search”},{:method=>“get”})do%> “提交”)%%>

执行此操作的最佳方法是什么?

逻辑将进入PartyController

类似于中的内容(语法可能有点错误):

PartyController.rb

def search
    result = params[:q]
    redirect_to '/parties/' + result
end

yeenow123给了你一个正确的方法,我只想澄清一些观点

“parties/hello”会将路由与parties/:id混淆(显示操作)
如果您不想使用show action,您应该从路由中删除它。rb:parties资源,或者您可以使用show action作为函数,其中params[:id]是您的搜索键,并继续执行此操作。

好的,这是有意义的-我遇到的唯一问题是,当我单击submit按钮时,它会点击我的“show”方法,而不是我的“search”方法如果我想让它先点击搜索方法(它重定向的地方),然后点击显示方法(它从数据库中呈现信息的地方)有办法指定吗?我认为您可以覆盖显示路由:-从route.rb中删除显示路由-将其替换为作为参与方的搜索操作/:query=>:search-使用:render、redirect\u或直接调用show方法在搜索操作中运行show方法,这取决于您和您的逻辑。