Coder Social home page Coder Social logo

Comments (5)

teeparham avatar teeparham commented on June 27, 2024

You could make helper methods for the buttons and do it like this:

posts_helper.rb

def edit_button(post)
  link_to "edit post", edit_post_path(post)
end

def delete_button(post)
  # delete button code
end

_index.html.erb

<%= render_cached 'post',
          collection: @posts,
          replace: { 
            edit_button: -> (post) { edit_button(post) },
            delete_button: -> (post) { delete_button(post) }
        }
%>

_post.html.erb

<tr>
  <td>Post name here</td>
  <td><%= cache_replace_key :edit_button %></td>
  <td><%= cache_replace_key :delete_button %></td>
</tr>

from cache_rocket.

amnesia7 avatar amnesia7 commented on June 27, 2024

Thanks @teeparham but is it not possible to mix keys and partials when replacing?

On Mon, Jan 19, 2015 4:37 PM GMT Tee Parham wrote:

You could make helper methods for the buttons and do it like this:

posts_helper.rb

def edit_button(post)

 link_to "edit post", edit_post_path(post)

end



def delete_button(post)

 # delete button code

end

_index.html.erb


<%= render_cached 'post',

         collection: @posts,

         replace: { 

           edit_button: -> (post) { edit_button(post) },

           delete_button: -> (post) { delete_button(post) }

       }

%>

_post.html.erb

<tr>

 <td>Post name here</td>

 <td><%= cache_replace_key :edit_button %></td>

 <td><%= cache_replace_key :delete_button %></td>

</tr>

Reply to this email directly or view it on GitHub:

#5 (comment)

from cache_rocket.

teeparham avatar teeparham commented on June 27, 2024

You cannot currently pass a partial as the replace value for each item in a collection. I'm not exactly sure how that would work. You could try something like:

<%= render_cached 'post',
          collection: @posts,
          replace: { 
            something: -> (post) { render partial: 'dynamic', post: post }
        }
%>

from cache_rocket.

amnesia7 avatar amnesia7 commented on June 27, 2024

Yep, that almost worked, but needed to be:

<%= render_cached 'post',
          collection: @posts,
          replace: { 
            something: -> (post) { render partial: 'dynamic', locals: { post: post } }
          }
%>

Thanks @teeparham

from cache_rocket.

amnesia7 avatar amnesia7 commented on June 27, 2024

@teeparham it might also be worth pointing out in the Use section of the gem's readme that you need to include loading cache_rocket from the lib directory because I don't think autoloading lib files is done by default.
I did this by adding an initializer file called cache_rocket.rb that just contained:

require 'cache_rocket'

from cache_rocket.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.