简体   繁体   English

局部渲染视图fie Rails

[英]Partial render view fie Rails

Hi I am working with application that show image according to the date we select for that I used date picker for selecting date and used searching concept for filter and select the element according to the date In view file I have called the resultant Image like this in my view file 嗨,我正在使用根据我们选择的日期显示图像的应用程序,我使用日期选择器选择日期,并使用搜索概念进行过滤,并根据日期选择元素。在视图文件中,我将生成的图像称为我的检视档案

-- search field -- -搜索字段-

 <div id="search_field" >
<%= search_form_for @search,  :id => "search_form"  do |f| %>
  <div id="field">
    <%= f.text_field :date_cont , :id  => 'search_box' %>
    </div>
    <%= f.submit %>
    <% end %>

-- result field - -结果字段-

 <div id="image">
  <%= render partial: 'image', format: 'js' %>

I have created a partial image with this code 我用此代码创建了部分图像

<% @posts.each do |post| %>
    <td><%= image_tag post.name %></td>

and my controller is 而我的控制器是

  def index   
 if params[:q]
    @search=Post.search(params[:q])
    @posts = @search.result
else
      @posts=Post.where(date: Date.today.strftime("%Y-%m-%d")) 
end

everything is working fine now what I want is when I click on the date entire page is reloading I want only the partial "image" has to be reloaded and give the resultant Image . 现在一切正常,当我单击整个页面重新加载的日期时,我想要的是我只需要重新加载部分“图像”并提供生成的Image。 What should I do? 我该怎么办? how to call This partial via Ajax? 如何通过Ajax将此部分调用? end 结束

Add a parameter 添加参数

remote: true

to your form tag. 到您的表单标签。

I'm on a cell phone now, can't explain better. 我现在在用手机,无法解释得更好。 Google 'Rails form remote true', you'll find a tutorial to follow. Google'Rails form remote remote',您会找到一个教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM