navinspm
navinspm

Reputation: 153

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 . What should I do? how to call This partial via Ajax? end

Upvotes: 1

Views: 74

Answers (1)

jlucasps
jlucasps

Reputation: 940

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.

Upvotes: 1

Related Questions