开发者

Creating records using RJS in rails

开发者 https://www.devze.com 2023-01-02 17:24 出处:网络
so I\'ve watched http://railscasts.com/episodes/43-ajax-with-rjs but I have a question: In my view I have the following:

so I've watched http://railscasts.com/episodes/43-ajax-with-rjs

but I have a question:

In my view I have the following:

<div id="testly">
    <%= render :partial => "test" %>
</div>

This works.

Using create.rjs to change the content in this div, I have the following in my create.rjs开发者_Python百科 file:

page.replace_html :testly, :partial => 'test'

Simply put, this should just refresh the partial right? But its not working... Would love any suggestions!


Also in regards to checking errors - I haven't been able to yet (as its on a different computer), but if I replace the :partial => "test" in create.rjs with "..." it replaces it just fine - making me believe it isn't an issue with the ajax?


I've done some more testing, the partial declaration works - what doesn't seem to work is calling the code in the partial through javascript.

The code in the partial is:

<% today=Time.now.strftime("%m/%d/%Y") %>
<% @books.each do |book| %>
<% if book.created_at.strftime("%m/%d/%Y")==today %>
<div class="item-book" style="clear:both;">
    <%=h book.author.name %>
</div>
<div class="item-delete">
    <%= link_to '<div class="delete"></div>', book, :confirm => 'Are you sure?', :method => :delete %>  
</div>
<div class="item-date">
    <%=h book.created_at.strftime("%m/%d/%Y") %>    
</div>
<% end %>
<% end %>


Ok so for now, I've solved this.

I made the partial part of a collection (in the view), and removed the loop from the partial.

Then in create.rjs I added :bottom, and the object and changed it to insert html (as seen in Ryan's video).

This did the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消