Ruby on Rails jQuery 视觉效果

发布于 2024-09-11 21:28:11 字数 1666 浏览 2 评论 0原文

我正在 RoR 上开发一个搜索功能,当用户单击搜索按钮时,它基本上会产生很酷的视觉效果。

这是我视图中的 search.rhtml 代码

  <html>
  <head>
    <title>Tutor</title>
    <%= javascript_include_tag :defaults %>
  </head>
  <body>
    <h1></h1>
        <%= form_remote_tag :url =>{ :action => :search_results }, :update => "results"  %>


                    <fieldset>
                        <legend>Tutor Search.</legend>
                        <label for="searchItField">Keyword Search.</label>

                        <input class="tfield" type="text" value="FIND YOUR TUTOR HERE" name="searchItField" id="searchItField" />
                        <span id="Submit_search">

                            <span id="Submit_search_hover"><input type="submit" id="Submit" value="Search" /></span>

                        </span>
                    </fieldset>
                </form>

    <div id="results">

    </div>
  </body>
</html>

这是 search_results.rhtml,它显示在 search.rhtml 的结果 div 中

<% for tutors in @tutors %>
        <%= tutors.first_name %> <br/>
    <% end %>

最后这是我的控制器和操作。

class TutorsController < ApplicationController

  def search
  end

  def search_results
     @tutors = Tutors.find_by_sql('SELECT * FROM tutors')
  end

end

我想要做的基本上是创建一个效果,当由于ajax调用而加载搜索结果时,它会向上滑动。我正在使用jrails。这个网站就是这么做的。 http://keyonary.com/#/paste

I am working on a search function on RoR that basically just has a cool visual effect when a user clicks the search button.

Here is the code in my view for search.rhtml

  <html>
  <head>
    <title>Tutor</title>
    <%= javascript_include_tag :defaults %>
  </head>
  <body>
    <h1></h1>
        <%= form_remote_tag :url =>{ :action => :search_results }, :update => "results"  %>


                    <fieldset>
                        <legend>Tutor Search.</legend>
                        <label for="searchItField">Keyword Search.</label>

                        <input class="tfield" type="text" value="FIND YOUR TUTOR HERE" name="searchItField" id="searchItField" />
                        <span id="Submit_search">

                            <span id="Submit_search_hover"><input type="submit" id="Submit" value="Search" /></span>

                        </span>
                    </fieldset>
                </form>

    <div id="results">

    </div>
  </body>
</html>

Here is the search_results.rhtml which is what gets displayed in the results div in search.rhtml

<% for tutors in @tutors %>
        <%= tutors.first_name %> <br/>
    <% end %>

And finally here is my controller and actions.

class TutorsController < ApplicationController

  def search
  end

  def search_results
     @tutors = Tutors.find_by_sql('SELECT * FROM tutors')
  end

end

What I want to do is basically create an effect that when the search results are loaded because of the ajax call that it would slide up. I am using jrails. Exactly how this site does it. http://keyonary.com/#/paste

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-09-18 21:28:11

简而言之,要开始使用,您需要执行以下操作:

  • 在输入字段上使用 observe_field,它从控制器方法检索数据,并使用结果更新某个 div,
  • 创建一个将检索项目的相应控制器方法(使用您的 search_results
  • 为该控制器方法创建一个视图,该视图将显示具有所需效果和动画的数据。

In short, to get you started, you will need to do the following:

  • use observe_field on the input-field, which retrieves data from a controller-method and will update a certain div with the results
  • create a corresponding controller-method that will retrieve the items (use your search_results)
  • create a view for that controller-method that will show the data with the required effects and animation.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文