Comments (5)
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.
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:
from cache_rocket.
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.
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.
@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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cache_rocket.