1
내 Rails 앱 사용자에게는 새로운 블로그 게시물을 만들 수있는 폴더가 있습니다. 사용자가 새 폴더를 작성할 때 모든 폴더 게시물을 포함하는 부분을 새로 고침하고 싶습니다. 나는 부분을 다시 호출하고 대체하는 폴더 컨트롤러에서 작업을 만들려고했지만 CanCan :: AccessDenied 500 오류가 발생합니다. 내 index.html.erb에서 ajax 콜백에서 부분로드 다시로드
이 내 폴더에 대한 링크 부분 쇼 : 이<%= link_to folder_path(folder), remote: true %>
여기에 그보기에로드되는 부분이다 :
<div id="panel-container">
<div id="entry-container" class="entry-window">
<div id="meta-bar" class="top">
<span id="location-span" style="position:relative; float:left;">In <%= @folder.title %></span>
<div id="entry-meta" class="meta-info">
<i class="icon-ok icons" id="save-entry"></i>
<i class="icon-remove icons" id="close" style="margin-left:10px"></i>
</div>
</div>
<div id="entry-create-partial" class="contain-entry">
<div id="title-create-partial" class="title-partial" name="title" contenteditable="true" data-placeholder='Title it' style="color:black"></div>
<div id="meta-popup"><button type="button" class="btn" id="nested-button">Create Nested Entry</button></div>
<div id="content-create-partial" class="content-partial" name="content" contenteditable="true" data-placeholder='Write anything' style="color:gray"></div>
</div>
</div>
<div id="container-edit" class="entry-window">
<span id="location-span" style="position:relative; float:left;">In <%= @folder.title %></span>
<div id="entry-meta" class="meta-info">
<button type="button" id="save-edit" class="btn">Save</button>
<button type="button" class="btn" id="close-edit"><i class="icon-remove" id="entry-cancel-x close-edit"></i>Cancel</button>
</div>
<div id="entry-edit-partial" class="contain-entry">
<div id="title-edit-partial" class="title-partial" name="title" contenteditable="true" style="color:black"></div>
<div id="content-edit-partial" class="content-partial" name="content" contenteditable="true" style="color:gray"></div>
</div>
</div>
<div id="right-panel">
<div id="top" class="top">
<h3><%= @folder.title %></h3>
<ul id="inner-list">
<button class="btn" id="journal-create-button">New Journal</button>
<div id="create-journal-drop">
<form action="/folders" method="post">
<%= hidden_field_tag :user_id, current_user.id %>
<%= hidden_field_tag :parent_id, @folder.id %>
<h3 id="journal-create-partial">New Sub-Journal</h3>
<input type="text" id="titleinput" name="title" placeholder="Title it"></input>
<button type="submit" class="md-close folder-create" id="folder-create">Create</button>
</form>
</div>
<button class="btn" id="entry-button">New Entry</button>
<button type="button" id="delete-button" class="btn"><i class="icon-remove"></i></button>
</ul>
</div>
<% if @folder.submissions.count > 0 %>
<svg id="submission-circles">
<circle></circle>
<circle></circle>
<circle></circle>
<circle></circle>
</svg>
<% else %>
<h2>It's quiet in here. Create a journal entry or sub-journal to get started!</h2>
<% end %>
</div>
</div>
내가 말했듯이, 나는 이 전체 부분을 다시로드하여 사용자가 전체 페이지 새로 고침을 수행하지 않아도 새로운 데이터가 반영되도록하는 것이 좋습니다.
def ajax_load_events
respond_to do |format|
format.js
format.html
end
end
Ajax_load_events.js :
$("#panel-container").replace_html('<%= escape_javascript(render(:partial => "contents", :locals => {:folder => @folder})).html_safe %>');
그리고 마지막으로, 내 AJAX 호출 :
$("#save-entry").click(function(){
$.ajax({
type: "POST",
url: "/submissions",
dataType: "json",
data: {title: $("#title-create-partial").text(), content: $("#content-create-partial").text(), folder_id: <%= @folder.id %>},
complete: function(){
$.get("/ajax_load_events/", {folder: <%= @folder.id %>}, null, "script");
}
});
})
나는이처럼 보이는 폴더 컨트롤러의 새로운 액션을 만들어 내 경로의 경로는 다음과 같습니다. RB :
get "/ajax_load_events(.:format)" => "folders#ajax_load_events"