0

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 %>
0bserver07
  • 3,390
  • 1
  • 28
  • 56

1 Answers1

1

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 %>

rboling
  • 717
  • 1
  • 4
  • 8
  • Okay, Progress :)! It says Ok 200 when I click on the button, but still nothing shows up! – 0bserver07 Jan 15 '14 at 19:04
  • 1
    I just edited my answer. Try placing single quotation marks instead of double quotation marks around <%= escape_javascript(...) %>. – rboling Jan 15 '14 at 19:10
  • The Problem is that I have a different action, and the action is not brining back the display action! – 0bserver07 Jan 15 '14 at 22:03
  • What action are you using to invoke the display action? – rboling Jan 15 '14 at 22:08
  • 1
    So when the user clicks on the button, the different action is invoked and the display action is never called? What is the source code of the other action? – rboling Jan 15 '14 at 22:18
  • So here is the scenario: User clicks on `display` display hits `<%= link_to "Display", activities_path, :remote => true %>` and the controller action is set default to `index` not `display` – 0bserver07 Jan 15 '14 at 22:23
  • Just modified my answer. You'll need to make additions to your routes .rb file, located in the config directory. – rboling Jan 15 '14 at 22:37