Ruby on Rails jQuery 视觉效果
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,要开始使用,您需要执行以下操作:
observe_field
,它从控制器方法检索数据,并使用结果更新某个 div,search_results
)In short, to get you started, you will need to do the following:
observe_field
on the input-field, which retrieves data from a controller-method and will update a certain div with the resultssearch_results
)