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 %>
1
  • @BillyChan it's now showing the content of the partial.
    – 0bserver07
    Jan 15, 2014 at 20:57

1 Answer 1

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

7
  • Okay, Progress :)! It says Ok 200 when I click on the button, but still nothing shows up!
    – 0bserver07
    Jan 15, 2014 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, 2014 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, 2014 at 22:03
  • What action are you using to invoke the display action?
    – rboling
    Jan 15, 2014 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, 2014 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.