neighborland / cache_rocket Goto Github PK
View Code? Open in Web Editor NEWRails rendering extension for more server-side html caching
License: MIT License
Rails rendering extension for more server-side html caching
License: MIT License
How would you go on for adding edit/delete buttons for each item in a collection so that they can be shown alongside the post name (for instance)?
Do you create each link using the Proc syntax and pass them in as keys which seems a little messy or is there a way to pass in post name as a key and pass in an object or an id or something for the edit / delete buttons?
posts/index.html.erb
<%= render_cached 'post',
collection: @posts,
replace: {
name: -> (post) { post.name },
...
%>
The kind of output I'm trying to get is (simplified):
<tr>
<td>Post name here</td>
<td><a href="/posts/1/edit">Edit</a></td>
<td><a href="/posts/1" data-method="delete">Delete</a></td>
</tr>
Thanks
Because CacheReplace::replace_from_hash
uses sub! rather than gsub! if cache_replace_key is used with the same key more than once in a view only the first occurrence is replaced with the proper value.
For example:
= hidden_field_tag :person_id, cache_replace_key(:person_id)
= %span{id: "my_span_#{cache_replace_key(:person_id)}"}
Would yield something like
<input type='hidden' value='1234'/>
<span id='my_span_<cr person_id>'>
Expected output would be
<input type='hidden' value='1234'/>
<span id='my_span_1234'>
When passing in:
<%= render_cached 'post',
collection: @posts,
replace: {
post_id: -> (post) { post.id.to_s },
...
%>
and trying to use it as part of a css class name:
<%= content_tag(:li, class: "js-post-#{cache_replace_key :post_id}", .... do %>
it fails to replace the key and leaves <li class="js-post-<cr post_id>"....>
in the html.
Is it because rails is converting the angle brackets to <
and >
before cache_digest can do a replace on them?
Is there a way around this or should I just pass the class string in as a key into the view?
<%= content_tag(:li, class: (cache_replace_key :list_item_class), ... do %>
Hey there,
I'm running into a problem that likely has an obvious solution.
I'm trying to use render_cached with a partial and a collection like so:
= render_cached "release_listbox", :collection => @releases, replace: { read_indicator: ->(release_listbox){read_indicator_helper(release_listbox)} }
_release_listbox.html.haml (Simplified):
= release_listbox.title
= cache_replace_key 'read_indicator'
However in the partial release_listbox
returns nil. However when using a standard render partial: "release_listbox" ...
the variable release_listbox
returns the individual release.
Am I (likely) doing something wrong?
Thank you for all your work on this gem btw.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.