मैं अपने ऐप में एक चैट सिस्टम लागू कर रहा था, जिसमें टिप्पणियों की सूची केवल AJAX सबमिट के साथ पुनः लोड की जाएगी।क्या कामिनरी अंकन उत्पन्न करने वाले यूआरएल को ठीक करने का कोई संभावित तरीका है?
कामिनरी पेजिनेशन का उपयोग वहां किया जाता है, लेकिन नई टिप्पणी सबमिट होने के बाद इसे इस तरह के यूआरएल में अजीब स्ट्रिंग मिलती है।
example-website.com/users/mike/refresh_part?_=1356906069855 & पेज = 2
और जब टिप्पणी अन्य में प्रस्तुत किया गया था कि वह अपने यूआरएल में और अधिक अजीब तर्क पैरामीटर हो जाता है नियंत्रक। केवल जब यह स्पैमिंग त्रुटि उत्पन्न यूआरएल के साथ macthed गया था:
example-website.com/shop/walmart/topic/20/comments?authenticity_token=9nUyEQ%2Fa0F114vUe16RXf7jhsPw%2B736E%2BKyZFjiWbkQ%3D & टिप्पणी [शरीर] = परीक्षण & प्रतिबद्ध = बनाएं टिप्पणी & पेज = 2 & UTF8 = ✓
कैसे मैं इसे ठीक कर सकते हैं?
मेरे कोड हैं
विचारों/उपयोगकर्ताओं/show.html.erb
<%= javascript_tag do %>
jQuery(document).ready(function() {
refreshPartial();
setInterval(refreshPartial, 5000)
});
function refreshPartial() {
$.ajax({
url: "<%= show_user_path(@user) %>/refresh_part",
type: "GET",
dataType: "script",
});
}
<% end %>
......
<span id="chat">
<%= render 'users/comment' %>
</span>
<%= render 'users/comment_input' %>
विचारों/उपयोगकर्ताओं/_comment.html.erb
<table>
<tr>
<th>ID</th>
<th>PIC</th>
<th>Body</th>
<th>Subject</th>
<th>Posted by</th>
<th>Delete</th>
</tr>
<% @comments.each do |comment| %>
<tr id="<%= dom_id(comment) %>">
<td><%= comment.id %></td>
<td>
<% if comment.comment_icon? %>
<ul class="thumbnails">
<%= image_tag(comment.comment_icon.url(:thumb),:height => 100, :width => 100, :style => 'border:3px double #545565;') %>
</ul>
<% end %>
</td>
<td><%= comment.body %></td>
<td><%= comment.subject %></td>
<td><%= comment.user.user_profile.nickname if comment.user.user_profile %></td>
<td>
<%= button_to 'destroy', polymorphic_path([@user, comment]), :data => {:confirm => 'Are you sure?'}, :method => :delete, :disable_with => 'deleting...', :remote => true, :class => 'btn btn-danger' if current_user && current_user.id == comment.user_id %>
</td>
</tr>
<% end %>
</table>
<%= paginate @comments, :window => 4, :outer_window => 5, :left => 2, :right => 2 %>
विचार/उपयोगकर्ता/_comment_input.html.erb< = यह इनपुट फॉर्म है !!!!!
<%=form_for(([@user, @comment]), :remote => true) do |f| %>
<div class="field">
<%= f.label :body %><br />
<%= f.text_field :body %>
</div>
<div class="field">
<%= f.file_field :comment_icon %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
comments_controller.rb
def create
commentable = @community_topic||@community||@user
@comments = commentable.comment_threads.order("updated_at DESC").page(params[:page]).per(5)
@comment = Comment.build_from(commentable, current_user.try(:id), params[:comment][:body])
@comment.comment_icon = params[:comment][:comment_icon]
if @user
@following_users = @user.all_following(order: 'updated_at DESC')
@followed_users = @user.followers
@communities_user = @user.get_up_voted(Community).order("updated_at ASC").page(params[:page]).per(5)
elsif @community
end
last_comment = Comment.where(:user_id => current_user.id).order("updated_at").last
if last_comment && (Time.now - last_comment.updated_at) <= 10.second
flash[:notice] = "You cannot spam!"
render :template => template_for(commentable)
elsif @comment.save
#if @community_topic.empty?
@comments = commentable.comment_threads.order("updated_at DESC").page(params[:page]).per(5)
@comment = commentable.comment_threads.build
respond_to do |format|
format.html { redirect_to [@community, commentable].uniq, :notice => "comment added!" }
format.js do
if @community.present?
render 'communities/refresh_part'
elsif @community_topic.present?
render 'community_topics/refresh_part'
elsif @user.present?
render 'users/refresh_part'
end
end
end
else
render :template => template_for(commentable)
end
end
विचारों/उपयोगकर्ताओं/refresh_part.js.erb
$('#chat').html("<%= j(render(:partial => 'users/comment')) %>")
बहुत बहुत धन्यवाद :) मैंने आपके सुझाव की कोशिश की। लेकिन ऐसा लगता है कि इसकी अक्षम ** दूरस्थ => सत्य ** :(क्या आप बता सकते हैं क्यों? मैंने यह ** <% = पेजिनेट at_comments,: window => 4,: outer_window => 5,: left => 2, : दाएं => 2,: पैराम्स => {: नियंत्रक => 'समुदायों',: क्रिया => 'शो', _: शून्य, _method: शून्य, प्रामाणिकता_टोकन: शून्य, utf8: nil}%> ** – MKK
ठीक है, आपको केवल 'paginate' के लिए तर्कों की अपनी सूची में ': remote => true' डालना होगा। – Andrew
बहुत बहुत धन्यवाद :) – MKK