I'm trying to get the activities when the user clicks on a button called display Controller:

 def display
    @activities =  Activity.all
    @activities = Activity.order("created_at desc")

    #we will need to find the Post id Through Users relation to the Comments
    #And this is because Activity Track, tracks Users actions, it breaks down from there.

    @posts = Post.all
    @user_comments = UserComment.all    
  respond_to do |format|               
    format.js { @activities = Activity.order("created_at desc") }
  end 

View:

<%= link_to "Display", activities_path, :remote => true %>
<div id="notify" class="section-link">  
   </div>

display.js.erb

$('#notify').append("<%= escape_javascript(render :partial => 'layouts/activity') %>");

_activity.html.erb

<% @activities.each do |activity| %>
      <%= ActivityPresenter.new(activity, self).render_activity %>
    <% end %>
有帮助吗?

解决方案

Try this in display.js.erb:

$('#notify').append('<%= escape_javascript(render :partial => 'layouts/activity', :collection => @activities) %>');

Then, try this in _activity.html.erb:

<%= ActivityPresenter.new(activity, self).render_activity %>

To ensure that whenever the user clicks on "Display' the display action is invoked, you will need to adjust your routes.rb file, which is located in the config directory. You could do something like this in routes.rb:

get '/activities/display', 'activities#display', as: :activity_display

Once you make that change in routes.rb, you can edit your link_to like this:

<%= link_to "Display", activity_display_path, :remote => true %>

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top