0

私はRails 3.2.13を使用しており、送信されたすべての投稿を一覧表示するインデックスビューを持っています。クリックするとカラーボックス(iframe)内に「投稿を作成」フォームが開き、クリックすると同じビューにボタンを追加しましたデータを送信すると保存されますが、新しく追加された投稿を表示するにはページを更新する必要があります..更新せずに送信をクリックした後に表示したい..

これは私のインデックスビューです:

> <h1>Listing posts</h1>
> 
> <table>   <tr>
>     <th>Name</th>
>     <th>Title</th>
>     <th>Content</th>
>     <th></th>
>     <th></th>
>     <th></th>   </tr> <div id="update-container">   <%= render 'show' %> </div>
> 
> </table> <div class="replace"></div>
> 
> <br /> <div></div>
> 
> <a href="" class="test">test</a> <a class='example5' title="My
> Page">Add a post</a> <br />
> 
> <%= link_to "Update User List", @show_path, :remote => true %>
> 
> 
> <%= link_to 'New Post', new_post_path %> <%= link_to "New post
> colorbox", "_form.html.erb", :data => { :colorbox => true,
> :colorbox_height => '300px' } %> <script type="text/javascript"> <%=
> render(:partial => 'posts', :handlers => [:erb], :formats => [:js]) %>
> </script>

これは _show パーシャルです:

<% @posts.each do |post| %>
  <tr>
        <td><%= post.name %></td>
    <td><%= post.title %></td>
    <td><%= post.content %></td>
    <td><%= link_to 'Show', post %></td>
    <td><%= link_to 'Edit', edit_post_path(post) %></td>
    <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' }, :remote => true, :class => 'delete_post' %></td>

  </tr>
<% end %>

およびjsファイル:

jQuery.ajaxSetup({
    'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

$(function(){

    $('.delete_post').bind('ajax:success', function() {
    $(this).closest('tr').fadeOut();
    });


     $(".example5").colorbox({width:"40%", 
        height:"100%", 
        iframe:true, 
        href:"posts/new", 
        scrolling:false,


     });



    m =$('.replace');
    m.innerHTML = "<%= escape_javascript(render :partial => "show") %>";
 });

私は基本的に1日半それを解決しようとしてきました。どんな助けでも大歓迎です。

更新:投稿フォーム

<div class="form">
<%= form_for(@post, :remote => true, :class =>"target", :method => "post") do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :content %><br />
    <%= f.text_area :content %>
  </div>
  <a href="" class="close">close</a>
  <div class="actions" id="target">
    <%= f.submit :disable_with => 'Please wait...', :class => 'submits'%>
  </div>
<% end %>
</div>
4

1 に答える 1