Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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_Ruby_Twitter Bootstrap_Web Applications - Fatal编程技术网

Html 我怎样才能加上?’;链接到';返回搜索结果'&引用;功能导轨

Html 我怎样才能加上?’;链接到';返回搜索结果'&引用;功能导轨,html,ruby-on-rails,ruby,twitter-bootstrap,web-applications,Html,Ruby On Rails,Ruby,Twitter Bootstrap,Web Applications,我有显示搜索结果的视图/search/search_tube.html.erb。当用户单击教科书.title by时,用户正在调用教科书\u控制器中的show方法 但是,在views/texties/show.html.erb中有,它只将用户带到教科书的索引页(views/texties/index.html.erb) 下面是我的页面,显示了搜索结果视图/search/search\u tubook.html.erb: <div class="container"> <d

我有显示搜索结果的
视图/search/search_tube.html.erb
。当用户单击教科书.title by
时,用户正在调用
教科书\u控制器中的
show
方法

但是,在
views/texties/show.html.erb
中有
,它只将用户带到教科书的索引页(
views/texties/index.html.erb

下面是我的页面,显示了搜索结果
视图/search/search\u tubook.html.erb

<div class="container">
   <div class="row">
      <div class="col-sm-12">        
         <table class = "table table-striped">
            <h1>Textbook Search Results</h1>

            <thead>
               <tr>
                  <th>Textbook Title</th>
                  <th>Subject</th>
                  <th>Price</th>
                  <th>Accept Offer</th>
                  <th>Created on</th>
               </tr>
            </thead>

          <tbody>
            <% @textbooks.each do |textbook| %>
              <tr>
                <!--<td><%= textbook.title %></td>-->
                <td><%=link_to "#{textbook.title}", textbook_path(textbook.id) %></td>
                <td><%= textbook.subject %></td>
                <td>$<%= textbook.price %></td>
                <td>
                  <% if textbook.offer == true %>
                    <!--<%= "\u2713"%>-->
                    <p class="offer_yes">&#x2713;</p>
                  <% else %>
                    <!--<%= "\u2715" %>-->
                    <p class="offer_no">&#x2715;</p>
                  <%end%>
                </td><!--somehow below need Date.parse()-->
                <td><%= textbook.created_at.strftime("%d %b. %Y") %></td>
              </tr>
            <% end %>
          </tbody>
        </table>

        <br>

        <div>
          <%= form_tag search_textbook_path, :method => :get do %>
            <p>
            <a style="color:#000000" title="Suggest!" data-toggle="popover" data-trigger="hover" data-content="Title or Subject">
              <%= text_field_tag :search, params[:search], placeholder: "Search textbooks" %>
            </a>
            <%= submit_tag "Search", :name => nil, class: "btn btn-success btn-sm" %>
          <% end %>
        </div>

        <%= link_to 'Sell Textbook', new_textbook_path, class: "btn btn-primary" %>
        <%= link_to 'Back to list', textbooks_path %>

        <script>
        $(document).ready(function(){
            $('[data-toggle="popover"]').popover();   
        });
        </script>

    </div>
  </div>
</div>

图像:

创建日期:

|
如果用户来自搜索结果,我如何添加clickalbe按钮返回搜索结果


谢谢

我本来会这样做的

1)找到当前路径并将其分配给闪存:

闪光灯不仅用于发送信息,实际上也是向其他操作发送临时数据的最简单方式。 因此,在教科书控制器的搜索操作中:

<p>
    <%if URI(request.referer).path == "/search_textbook" %>
       <%= link_to 'Back to Search Result', request.referer, class: "btn btn-warning" %>
    <%end%>
</p>
注意:
[当前路径]
不是ruby代码,我们稍后将看到如何找到它

2)使用教科书放映视图中的链接:

在教科书放映视图中,您需要做的是:


但是。。。您如何找到[当前路径]? 显然[当前路径]不是ruby代码,因此您必须用其他代码替换它。 有多种方法可以找到当前路径或url:look和

闪烁?

flash对于传递临时数据非常有用,我强烈建议您阅读更多关于flash的内容

在操作之间传递数据的其他解决方案

您可以使用params传递该链接参数,但这会增加复杂性


您也可以使用cookies,但这会将其保存到用户浏览器中,并且只有当他来自搜索结果时才起作用:

以上flash是一个好方法。但我用下面的方式



这太棒了!非常感谢。但我的搜索操作不在教科书控制器中。
search
操作在
search\u控制器中
我应该更换吗?它可以工作!但是我想隐藏这条快闪信息。很高兴这对你有用!当你进入下一个动作时,无论你的动作在哪里,你都可以访问flash对象。闪光信息通常只是一条信息,当闪光存在时显示闪光值。flash[:notice]与flash[:last_search_path]的功能完全相同,唯一的区别是它会显示一条消息,检查应用程序布局视图文件,看看您有哪些条件。我发现flash很好,但我找到了更好的答案并尝试了。看下面!无论如何,谢谢你。
flash[:last_search_path] = [the current path]
<% if flash[:last_search_path] %>
  <%= link_to "back to search results", flash[:last_search_path] %>
<% end %>
<p>
    <%if URI(request.referer).path == "/search_textbook" %>
       <%= link_to 'Back to Search Result', request.referer, class: "btn btn-warning" %>
    <%end%>
</p>