Ruby on Rails Thursday, June 22, 2017

I've started to use wicked_pdf and it works fine.  However, when I generate a PDF files, usually the CPU will get to ~80+% during the generation of the PDF by the wicked_pdf gem.  What's the proper way of handling this in my application?  I've asked around on IRC chat, stack overflow, etc, but I haven't been able to acquire a good answer.  People have told me to use Sidekiq, which I have, but this won't resolve my CPU issue unless I've put the job processes onto another machine it would seem.  Is there another way of handling this using my one server?

If it's helpful here is the stack overflow question that I posted about 12 days ago - it has perhaps a little more detail: 

Please let me know if I can provide more details on any aspect of this issue. Thanks!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/283aad1e-6be4-46ab-af8c-44425002f547%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails Wednesday, June 21, 2017

Dear All,

Just to confirm the subject, since I am new to Rails 5 (coming from Rails 4)....

The scaffold for controllers generates test cases that derive from "ActionDispatch::IntegrationTest", which makes the controller tests 
being, in fact, integration tests. Am I right? Basically, I understand that Rails 5 favours integration tests over old style controller unit tests.
Correct?

It's awesome if it does, btw.

Best

Pano

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bfed0e13-0565-42f3-9ca9-57b0a8d91948%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

> On Jun 21, 2017, at 3:52 AM, fugee ohu <fugee279@gmail.com> wrote:
>
> How do I give new.js.erb the right element name
> $('#comment_post)click.(function(){
> In this line there's no id number

I think you may have missed a few bits of my reply. We are not observing a click any more. Everything is out of the jQuery pool, and fully into the RJS pool. If you're viewing this in the Google Groups (Web) view, you may need to expand all of the little ... ellipses in order to see all of my threaded replies.

Walter

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/C456D1E6-2B3A-4316-AD3A-CC3A3055EBB3%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Tuesday, June 20, 2017 at 8:52:58 AM UTC-4, Walter Lee Davis wrote:

> On Jun 20, 2017, at 3:29 AM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Sunday, June 18, 2017 at 11:30:27 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 18, 2017, at 8:24 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Friday, June 16, 2017 at 6:47:49 PM UTC-4, Walter Lee Davis wrote:
> > There can only be one instance of an ID on any given page. And nothing you did in this example will render the id #commentable. If you look at my example, I did not use an ID on each element. The selector in $('#commentable').each should be $('#parent_of_the_list div'), and you'll have to apply whatever ID you want to search for to a parent element of the commentables. If you want to do this in a slightly simpler manner, you could apply a classname to the commentables, using the div_for helper: <%= div_for(commentable, class: 'commentable') do %>. Then you can change the jQuery to $('.commentable') and that will also work.
> >
> > Walter
> >
> > > On Jun 16, 2017, at 4:14 PM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > > The anchor doesn't get rendered I didn't know what to use for the element name so I used the same as I used the same variable I passed to div_for in my view, commentable Thanks in advance
> > >
> > >
> > > View:
> > >  <%= div_for(commentable) do %>
> > >  <% end %>
> > >
> > > js.erb
> > > $(document).on('turbolinks:load', function(){
> > >   $('#commentable').each(function(){
> > >     var elm = $(this);
> > >     elm.append('<a href="/comments/new?commentable_id=' + elm.attr('id').split('_')[1] + '">Comment</a>');
> > >           });
> > > });
> > >
> > >
> >
> >
> >  Here's my page souce and js.erb it's not appening anything to the page with the render
> >
> > <div class="post">
> >   <p>Doing nothing as usual</p>
> >  
> >
> >   <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> > </div>
> > <div class="post" id="post_14">
> > </div>
> >
> > $(document).on('turbolinks:load', function(){
> >   $('#post div').click.(function(){
> >     var elm = $(this);
> >     elm.append('<%= form_for @comment do |f| %>  <%= f.hidden_field :commentable_id, value: @comment.commentable_id %><%= f.hidden_field :commentable_type, value: @comment.commentable_type %>  <div class="field form-group">                <%= f.text_area :body, class: 'form-control' %>          </div>          <div class="field form-group">                <%= submit_tag "Post comment", class: 'btn btn-primary' %>          </div>        <% end %>');
> >   });
> > });
> >  
>
> You've skipped over the last set of instructions I sent you, and you really need to do this in order or it will never make sense. Show me the code you are using that loads the form into another page, and please don't post it unless it is working in a browser and you can save comments. Get that far, and THEN I will be happy to help you take it into Ajax land.
>
> Walter
>
>  _post.html.erb
>
> <%= content_tag_for(:div, post) do %>
>     <%= simple_format post.content %>
>     <% unless post.attachment.blank? %>
>       <%= image_tag(post.attachment, height: 250) %><br>
>     <% end %>
>     <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
>     <%= content_tag_for(:div, post, :comment) do %>

You may want to insert the existing comments here:

<%= render post.comments %>

Then you can inject the form at the top or the bottom of the list. Remember, you'll need a _comment.html.erb partial in the views/comments folder for the short-hand to work.

>     <% end %>
> <% end %>
>
> produces
>
> <div class="post" id="post_13">
>         <p>listening to blues</p>
>  
>
>         <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=13&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
>         <div class="comment_post" id="comment_post_13">
> </div></div><div class="post" id="post_14">
>         <p>Doing nothing as usual</p>
>  
>
>         <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
>         <div class="comment_post" id="comment_post_14">
> </div></div>
>
> new.js.erb
>   $('#post comment div)click.(function(){
>
> This doesn't produce anything

That's not surprising. Your RJS handler is going to be rendered with the same parameters that new.html.erb is when it creates a new page. So what you do in that instance is not observe a click (that click already happened) but rather identify the parts of the page that you want to replace, and replace them with the parts you need to insert. You're already on the other side of the click.

The content_tag_for method has a partner: dom_id(element, name_addition=nil). It produces just the ID for the element, not the entire element.

Inside the new.js.erb, rather than having the <%= render 'form' %> just spew out some HTML, you target where that should go:

$('#<%= dom_id(post, :comment) %>').prepend('<%=j render( 'comments/form' ) %>');

That will expand to $('#comment_post_14').prepend('<form ... >'); which will inject the form into the top of the comment_post_N container.

Trouble is, it will also do that again and again if you click the link repeatedly. To get around that, you could put the link to add a comment inside the container you want to fill with the form, and then use the jQuery html() method to replace the contents. That would look the same as above, just replace prepend with html. This gets around you needing to test if the form is already there, because the moment you click the link, the link is replaced with the form and you can't click it again.

So you have something like this in the end:

<%= content_tag_for(:div, post) do %>
    <%= simple_format post.content %>
    <% unless post.attachment.blank? %>
      <%= image_tag(post.attachment, height: 250) %><br>
    <% end %>
    <%= content_tag_for(:div, post, :new_comment) do %>
      <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
    <% end %>
    <%= content_tag_for(:div, post, :comments) do %>
      <%= render post.comments %>
    <% end %>
<% end %>

The new.js.erb becomes this:

$('#<%= dom_id(post, :new_comment) %>').html('<%=j render( 'comments/form' ) %>');

And then to update the page, you want to render just that post again into the list. This is why you wanted to have the posts/index.html.erb depend on a _post.html.erb partial to render the list -- you're automatically set up to do this last step.

Make sure that your form_for method includes the remote: true configuration pair. This will submit the form via Ajax.

In comments_controller.rb, make sure you have a respond_to block for :js in the #create method. In case of an error, it will need to render the :new method again, but if the save succeeds, it should just render the create.js.erb by default (pass an empty block to that content_for).

create.js.erb would be something like this:

$('#<%= dom_id(@comment.post) %>').replaceWith('<%=j render @comment.post %>');

And that's really it. If it doesn't work, it's probably a typo on my part.

Walter


>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3fea1525-2b10-4718-9fa0-b6d04216aa51%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


How do I give new.js.erb the right element name
   $('#comment_post)click.(function(){
In this line there's no id number

 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/86014d0a-3224-497e-a78c-4866e879ac0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Tuesday, June 20, 2017 at 8:52:58 AM UTC-4, Walter Lee Davis wrote:

> On Jun 20, 2017, at 3:29 AM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Sunday, June 18, 2017 at 11:30:27 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 18, 2017, at 8:24 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Friday, June 16, 2017 at 6:47:49 PM UTC-4, Walter Lee Davis wrote:
> > There can only be one instance of an ID on any given page. And nothing you did in this example will render the id #commentable. If you look at my example, I did not use an ID on each element. The selector in $('#commentable').each should be $('#parent_of_the_list div'), and you'll have to apply whatever ID you want to search for to a parent element of the commentables. If you want to do this in a slightly simpler manner, you could apply a classname to the commentables, using the div_for helper: <%= div_for(commentable, class: 'commentable') do %>. Then you can change the jQuery to $('.commentable') and that will also work.
> >
> > Walter
> >
> > > On Jun 16, 2017, at 4:14 PM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > > The anchor doesn't get rendered I didn't know what to use for the element name so I used the same as I used the same variable I passed to div_for in my view, commentable Thanks in advance
> > >
> > >
> > > View:
> > >  <%= div_for(commentable) do %>
> > >  <% end %>
> > >
> > > js.erb
> > > $(document).on('turbolinks:load', function(){
> > >   $('#commentable').each(function(){
> > >     var elm = $(this);
> > >     elm.append('<a href="/comments/new?commentable_id=' + elm.attr('id').split('_')[1] + '">Comment</a>');
> > >           });
> > > });
> > >
> > >
> >
> >
> >  Here's my page souce and js.erb it's not appening anything to the page with the render
> >
> > <div class="post">
> >   <p>Doing nothing as usual</p>
> >  
> >
> >   <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> > </div>
> > <div class="post" id="post_14">
> > </div>
> >
> > $(document).on('turbolinks:load', function(){
> >   $('#post div').click.(function(){
> >     var elm = $(this);
> >     elm.append('<%= form_for @comment do |f| %>  <%= f.hidden_field :commentable_id, value: @comment.commentable_id %><%= f.hidden_field :commentable_type, value: @comment.commentable_type %>  <div class="field form-group">                <%= f.text_area :body, class: 'form-control' %>          </div>          <div class="field form-group">                <%= submit_tag "Post comment", class: 'btn btn-primary' %>          </div>        <% end %>');
> >   });
> > });
> >  
>
> You've skipped over the last set of instructions I sent you, and you really need to do this in order or it will never make sense. Show me the code you are using that loads the form into another page, and please don't post it unless it is working in a browser and you can save comments. Get that far, and THEN I will be happy to help you take it into Ajax land.
>
> Walter
>
>  _post.html.erb
>
> <%= content_tag_for(:div, post) do %>
>     <%= simple_format post.content %>
>     <% unless post.attachment.blank? %>
>       <%= image_tag(post.attachment, height: 250) %><br>
>     <% end %>
>     <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
>     <%= content_tag_for(:div, post, :comment) do %>

You may want to insert the existing comments here:

<%= render post.comments %>

Then you can inject the form at the top or the bottom of the list. Remember, you'll need a _comment.html.erb partial in the views/comments folder for the short-hand to work.

>     <% end %>
> <% end %>
>
> produces
>
> <div class="post" id="post_13">
>         <p>listening to blues</p>
>  
>
>         <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=13&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
>         <div class="comment_post" id="comment_post_13">
> </div></div><div class="post" id="post_14">
>         <p>Doing nothing as usual</p>
>  
>
>         <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
>         <div class="comment_post" id="comment_post_14">
> </div></div>
>
> new.js.erb
>   $('#post comment div)click.(function(){
>
> This doesn't produce anything

That's not surprising. Your RJS handler is going to be rendered with the same parameters that new.html.erb is when it creates a new page. So what you do in that instance is not observe a click (that click already happened) but rather identify the parts of the page that you want to replace, and replace them with the parts you need to insert. You're already on the other side of the click.

The content_tag_for method has a partner: dom_id(element, name_addition=nil). It produces just the ID for the element, not the entire element.

Inside the new.js.erb, rather than having the <%= render 'form' %> just spew out some HTML, you target where that should go:

$('#<%= dom_id(post, :comment) %>').prepend('<%=j render( 'comments/form' ) %>');

That will expand to $('#comment_post_14').prepend('<form ... >'); which will inject the form into the top of the comment_post_N container.

Trouble is, it will also do that again and again if you click the link repeatedly. To get around that, you could put the link to add a comment inside the container you want to fill with the form, and then use the jQuery html() method to replace the contents. That would look the same as above, just replace prepend with html. This gets around you needing to test if the form is already there, because the moment you click the link, the link is replaced with the form and you can't click it again.

So you have something like this in the end:

<%= content_tag_for(:div, post) do %>
    <%= simple_format post.content %>
    <% unless post.attachment.blank? %>
      <%= image_tag(post.attachment, height: 250) %><br>
    <% end %>
    <%= content_tag_for(:div, post, :new_comment) do %>
      <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
    <% end %>
    <%= content_tag_for(:div, post, :comments) do %>
      <%= render post.comments %>
    <% end %>
<% end %>

The new.js.erb becomes this:

$('#<%= dom_id(post, :new_comment) %>').html('<%=j render( 'comments/form' ) %>');

And then to update the page, you want to render just that post again into the list. This is why you wanted to have the posts/index.html.erb depend on a _post.html.erb partial to render the list -- you're automatically set up to do this last step.

Make sure that your form_for method includes the remote: true configuration pair. This will submit the form via Ajax.

In comments_controller.rb, make sure you have a respond_to block for :js in the #create method. In case of an error, it will need to render the :new method again, but if the save succeeds, it should just render the create.js.erb by default (pass an empty block to that content_for).

create.js.erb would be something like this:

$('#<%= dom_id(@comment.post) %>').replaceWith('<%=j render @comment.post %>');

And that's really it. If it doesn't work, it's probably a typo on my part.

Walter


>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3fea1525-2b10-4718-9fa0-b6d04216aa51%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


List comments and inject the form at the top or bottom of the list, what about a link to new comment we skipped over that no?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6e4181c9-5e44-40f4-ab04-361a8f0906c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails Tuesday, June 20, 2017

> On Jun 20, 2017, at 2:57 PM, fugee ohu <fugee279@gmail.com> wrote:
>
> <%= content_tag_for(:div, post) do %>
> <%= simple_format post.content %>
> <% unless post.attachment.blank? %>
> <%= image_tag(post.attachment, height: 250) %><br>
> <% end %>
> <%= content_tag_for(:div, post, :new_comment) do %>
> <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
> <% end %>
> <%= content_tag_for(:div, post, :comments) do %>
> <%= render post.comments %>
> <% end %>
> <% end %>


This part would go into _post.html.erb

Walter

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/16432F1F-E312-44BE-9577-23E9D6A253EB%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Yes, I tried it.  But it expired after a couple of days.  

On Tuesday, June 20, 2017 at 4:29:57 PM UTC-4, Hassan Schroeder wrote:
On Tue, Jun 20, 2017 at 12:47 PM, Joe Guerra <JGu...@jginfosys.com> wrote:
> Is this a useful tool for web development?  I thought about purchasing it
> and learning/using it, but I don't know how well it fits in with ruby on
> rails and other stuff.
> I am a weak programmer, and even weaker designer  (I prefer black and white
> text).

It's a tool for UI/UX designers, but only you can decide whether it's
useful for your work.

There's a free trial version - why not test-drive that and decide?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bf8f2b93-f000-4ab7-926d-f159f6192ef2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

On Tue, Jun 20, 2017 at 12:47 PM, Joe Guerra <JGuerra@jginfosys.com> wrote:
> Is this a useful tool for web development? I thought about purchasing it
> and learning/using it, but I don't know how well it fits in with ruby on
> rails and other stuff.
> I am a weak programmer, and even weaker designer (I prefer black and white
> text).

It's a tool for UI/UX designers, but only you can decide whether it's
useful for your work.

There's a free trial version - why not test-drive that and decide?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yCMh4xSLrYc8raPzFhEH1-LB35BAMjs3zGk0povYKK8Mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Is this a useful tool for web development?  I thought about purchasing it and learning/using it, but I don't know how well it fits in with ruby on rails and other stuff.
I am a weak programmer, and even weaker designer  (I prefer black and white text).  

Thanks,
Joe

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/551330e8-ac6a-4280-8e33-507777b2d8f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Tuesday, June 20, 2017 at 8:52:58 AM UTC-4, Walter Lee Davis wrote:

> On Jun 20, 2017, at 3:29 AM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Sunday, June 18, 2017 at 11:30:27 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 18, 2017, at 8:24 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Friday, June 16, 2017 at 6:47:49 PM UTC-4, Walter Lee Davis wrote:
> > There can only be one instance of an ID on any given page. And nothing you did in this example will render the id #commentable. If you look at my example, I did not use an ID on each element. The selector in $('#commentable').each should be $('#parent_of_the_list div'), and you'll have to apply whatever ID you want to search for to a parent element of the commentables. If you want to do this in a slightly simpler manner, you could apply a classname to the commentables, using the div_for helper: <%= div_for(commentable, class: 'commentable') do %>. Then you can change the jQuery to $('.commentable') and that will also work.
> >
> > Walter
> >
> > > On Jun 16, 2017, at 4:14 PM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > > The anchor doesn't get rendered I didn't know what to use for the element name so I used the same as I used the same variable I passed to div_for in my view, commentable Thanks in advance
> > >
> > >
> > > View:
> > >  <%= div_for(commentable) do %>
> > >  <% end %>
> > >
> > > js.erb
> > > $(document).on('turbolinks:load', function(){
> > >   $('#commentable').each(function(){
> > >     var elm = $(this);
> > >     elm.append('<a href="/comments/new?commentable_id=' + elm.attr('id').split('_')[1] + '">Comment</a>');
> > >           });
> > > });
> > >
> > >
> >
> >
> >  Here's my page souce and js.erb it's not appening anything to the page with the render
> >
> > <div class="post">
> >   <p>Doing nothing as usual</p>
> >  
> >
> >   <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> > </div>
> > <div class="post" id="post_14">
> > </div>
> >
> > $(document).on('turbolinks:load', function(){
> >   $('#post div').click.(function(){
> >     var elm = $(this);
> >     elm.append('<%= form_for @comment do |f| %>  <%= f.hidden_field :commentable_id, value: @comment.commentable_id %><%= f.hidden_field :commentable_type, value: @comment.commentable_type %>  <div class="field form-group">                <%= f.text_area :body, class: 'form-control' %>          </div>          <div class="field form-group">                <%= submit_tag "Post comment", class: 'btn btn-primary' %>          </div>        <% end %>');
> >   });
> > });
> >  
>
> You've skipped over the last set of instructions I sent you, and you really need to do this in order or it will never make sense. Show me the code you are using that loads the form into another page, and please don't post it unless it is working in a browser and you can save comments. Get that far, and THEN I will be happy to help you take it into Ajax land.
>
> Walter
>
>  _post.html.erb
>
> <%= content_tag_for(:div, post) do %>
>     <%= simple_format post.content %>
>     <% unless post.attachment.blank? %>
>       <%= image_tag(post.attachment, height: 250) %><br>
>     <% end %>
>     <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
>     <%= content_tag_for(:div, post, :comment) do %>

You may want to insert the existing comments here:

<%= render post.comments %>

Then you can inject the form at the top or the bottom of the list. Remember, you'll need a _comment.html.erb partial in the views/comments folder for the short-hand to work.

>     <% end %>
> <% end %>
>
> produces
>
> <div class="post" id="post_13">
>         <p>listening to blues</p>
>  
>
>         <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=13&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
>         <div class="comment_post" id="comment_post_13">
> </div></div><div class="post" id="post_14">
>         <p>Doing nothing as usual</p>
>  
>
>         <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
>         <div class="comment_post" id="comment_post_14">
> </div></div>
>
> new.js.erb
>   $('#post comment div)click.(function(){
>
> This doesn't produce anything

That's not surprising. Your RJS handler is going to be rendered with the same parameters that new.html.erb is when it creates a new page. So what you do in that instance is not observe a click (that click already happened) but rather identify the parts of the page that you want to replace, and replace them with the parts you need to insert. You're already on the other side of the click.

The content_tag_for method has a partner: dom_id(element, name_addition=nil). It produces just the ID for the element, not the entire element.

Inside the new.js.erb, rather than having the <%= render 'form' %> just spew out some HTML, you target where that should go:

$('#<%= dom_id(post, :comment) %>').prepend('<%=j render( 'comments/form' ) %>');

That will expand to $('#comment_post_14').prepend('<form ... >'); which will inject the form into the top of the comment_post_N container.

Trouble is, it will also do that again and again if you click the link repeatedly. To get around that, you could put the link to add a comment inside the container you want to fill with the form, and then use the jQuery html() method to replace the contents. That would look the same as above, just replace prepend with html. This gets around you needing to test if the form is already there, because the moment you click the link, the link is replaced with the form and you can't click it again.

So you have something like this in the end:

<%= content_tag_for(:div, post) do %>
    <%= simple_format post.content %>
    <% unless post.attachment.blank? %>
      <%= image_tag(post.attachment, height: 250) %><br>
    <% end %>
    <%= content_tag_for(:div, post, :new_comment) do %>
      <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
    <% end %>
    <%= content_tag_for(:div, post, :comments) do %>
      <%= render post.comments %>
    <% end %>
<% end %>

The new.js.erb becomes this:

$('#<%= dom_id(post, :new_comment) %>').html('<%=j render( 'comments/form' ) %>');

And then to update the page, you want to render just that post again into the list. This is why you wanted to have the posts/index.html.erb depend on a _post.html.erb partial to render the list -- you're automatically set up to do this last step.

Make sure that your form_for method includes the remote: true configuration pair. This will submit the form via Ajax.

In comments_controller.rb, make sure you have a respond_to block for :js in the #create method. In case of an error, it will need to render the :new method again, but if the save succeeds, it should just render the create.js.erb by default (pass an empty block to that content_for).

create.js.erb would be something like this:

$('#<%= dom_id(@comment.post) %>').replaceWith('<%=j render @comment.post %>');

And that's really it. If it doesn't work, it's probably a typo on my part.

Walter


>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3fea1525-2b10-4718-9fa0-b6d04216aa51%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

In _post.html.erb ?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/35c41e75-38a8-4995-8ece-9e54ee13c530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hi,

I've been investigating an issue we've experienced the last few weeks since upgrading to Rails 5 and was hoping to see if anyone had an insight.

Issue: 
Every so often after our Rails server starts our API will return null for one enum on one model even though the enum's backing field is non-null in the database. Restarting the Rails server fixes the issue.

Setup:
Heroku + PostGres
ruby 2.4.1
rails 5.0.2
puma 3.9.0
(any many other gems)

I've tried reproducing this locally by running a script to start and stop the rails server to see if that would reproduce it, but found nothing after several hours.

Reading through the enum.rb module it looks like this could happen if the EnumType @mapping variable was empty, but I don't see how that would happen in practice, as it should be initialized when the enum is defined when loading all the ActiveRecord models.

Any ideas?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4fd93286-c5f0-476f-aaa7-f65032b28cf3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Hi everyone,

I am happy to announce that Rails 5.1.2.rc1 has been released.

If no regressions are found, expect the final release on Monday, June 26, 2017.
If you find one, please open an [issue on GitHub](https://github.com/rails/rails/issues/new)
and mention me (@rafaelfranca) on it, so that we can fix it before the final release.

## CHANGES since 5.1.1

To view the changes for each gem, please read the changelogs on GitHub:

* [Action Cable CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/actioncable/CHANGELOG.md)
* [Action Mailer CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/actionmailer/CHANGELOG.md)
* [Action Pack CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/actionpack/CHANGELOG.md)
* [Action View CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/actionview/CHANGELOG.md)
* [Active Job CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/activejob/CHANGELOG.md)
* [Active Model CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/activemodel/CHANGELOG.md)
* [Active Record CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/activerecord/CHANGELOG.md)
* [Active Support CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/activesupport/CHANGELOG.md)
* [Railties CHANGELOG](https://github.com/rails/rails/blob/v5.1.2.rc1/railties/CHANGELOG.md)

*Full listing*

To see the full list of changes, [check out all the commits on
GitHub](https://github.com/rails/rails/compare/v5.1.1...v5.1.2.rc1).

## SHA-256

If you'd like to verify that your gem is the same as the one I've uploaded,
please use these SHA-256 hashes.

Here are the checksums for 5.1.2.rc1:

```
$ shasum -a 256 *-5.1.2.rc1.gem
ae90de7d8f5d1129a162e9419b65e08870a433ed4eb067bcd44be161de394773  actioncable-5.1.2.rc1.gem
bd7b3ac7dacb1a983bf2b5dcc56255261421285ef9b5cc5d645d416a1ba42378  actionmailer-5.1.2.rc1.gem
21b097d2ea1009eaad2487b4461f20a2c76d2ea9786e2fb37dd1e87116ca3621  actionpack-5.1.2.rc1.gem
689d6580dbef9c81e43fc77185a7916ef7ca2a3d863300f6e47d8199e4bdbd1c  actionview-5.1.2.rc1.gem
dfa1afc5d701241e25282c318738a8c379fdbd9cf682725f87e1c16584bf3be6  activejob-5.1.2.rc1.gem
040c3aaa4bf7686efa0e716dc4cf077d4d5b1ef598c81f7d32e86f1f8f26817a  activemodel-5.1.2.rc1.gem
8bc8b1677051975083717c65a3ee3df612b5e9d381db9d90dc71f3484f514a0b  activerecord-5.1.2.rc1.gem
69aab1c234f1223ceedb62168df071bdb3483a00be5e186278983eb1ed636e69  activesupport-5.1.2.rc1.gem
50a14c6e4952297f0a9a510b268ea845833474dccbe1619594c0406ceab5c7fa  rails-5.1.2.rc1.gem
7c18b3a185f73740b020ecf9414ea8d5c254edddefce64e7383bd137c7626d45  railties-5.1.2.rc1.gem

```

As always, huge thanks to the many contributors who helped with this release.

Ruby on Rails

> On Jun 20, 2017, at 3:29 AM, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Sunday, June 18, 2017 at 11:30:27 PM UTC-4, Walter Lee Davis wrote:
>
> > On Jun 18, 2017, at 8:24 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> >
> >
> > On Friday, June 16, 2017 at 6:47:49 PM UTC-4, Walter Lee Davis wrote:
> > There can only be one instance of an ID on any given page. And nothing you did in this example will render the id #commentable. If you look at my example, I did not use an ID on each element. The selector in $('#commentable').each should be $('#parent_of_the_list div'), and you'll have to apply whatever ID you want to search for to a parent element of the commentables. If you want to do this in a slightly simpler manner, you could apply a classname to the commentables, using the div_for helper: <%= div_for(commentable, class: 'commentable') do %>. Then you can change the jQuery to $('.commentable') and that will also work.
> >
> > Walter
> >
> > > On Jun 16, 2017, at 4:14 PM, fugee ohu <fuge...@gmail.com> wrote:
> > >
> > > The anchor doesn't get rendered I didn't know what to use for the element name so I used the same as I used the same variable I passed to div_for in my view, commentable Thanks in advance
> > >
> > >
> > > View:
> > > <%= div_for(commentable) do %>
> > > <% end %>
> > >
> > > js.erb
> > > $(document).on('turbolinks:load', function(){
> > > $('#commentable').each(function(){
> > > var elm = $(this);
> > > elm.append('<a href="/comments/new?commentable_id=' + elm.attr('id').split('_')[1] + '">Comment</a>');
> > > });
> > > });
> > >
> > >
> >
> >
> > Here's my page souce and js.erb it's not appening anything to the page with the render
> >
> > <div class="post">
> > <p>Doing nothing as usual</p>
> >
> >
> > <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> > </div>
> > <div class="post" id="post_14">
> > </div>
> >
> > $(document).on('turbolinks:load', function(){
> > $('#post div').click.(function(){
> > var elm = $(this);
> > elm.append('<%= form_for @comment do |f| %> <%= f.hidden_field :commentable_id, value: @comment.commentable_id %><%= f.hidden_field :commentable_type, value: @comment.commentable_type %> <div class="field form-group"> <%= f.text_area :body, class: 'form-control' %> </div> <div class="field form-group"> <%= submit_tag "Post comment", class: 'btn btn-primary' %> </div> <% end %>');
> > });
> > });
> >
>
> You've skipped over the last set of instructions I sent you, and you really need to do this in order or it will never make sense. Show me the code you are using that loads the form into another page, and please don't post it unless it is working in a browser and you can save comments. Get that far, and THEN I will be happy to help you take it into Ajax land.
>
> Walter
>
> _post.html.erb
>
> <%= content_tag_for(:div, post) do %>
> <%= simple_format post.content %>
> <% unless post.attachment.blank? %>
> <%= image_tag(post.attachment, height: 250) %><br>
> <% end %>
> <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
> <%= content_tag_for(:div, post, :comment) do %>

You may want to insert the existing comments here:

<%= render post.comments %>

Then you can inject the form at the top or the bottom of the list. Remember, you'll need a _comment.html.erb partial in the views/comments folder for the short-hand to work.

> <% end %>
> <% end %>
>
> produces
>
> <div class="post" id="post_13">
> <p>listening to blues</p>
>
>
> <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=13&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> <div class="comment_post" id="comment_post_13">
> </div></div><div class="post" id="post_14">
> <p>Doing nothing as usual</p>
>
>
> <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> <div class="comment_post" id="comment_post_14">
> </div></div>
>
> new.js.erb
> $('#post comment div)click.(function(){
>
> This doesn't produce anything

That's not surprising. Your RJS handler is going to be rendered with the same parameters that new.html.erb is when it creates a new page. So what you do in that instance is not observe a click (that click already happened) but rather identify the parts of the page that you want to replace, and replace them with the parts you need to insert. You're already on the other side of the click.

The content_tag_for method has a partner: dom_id(element, name_addition=nil). It produces just the ID for the element, not the entire element.

Inside the new.js.erb, rather than having the <%= render 'form' %> just spew out some HTML, you target where that should go:

$('#<%= dom_id(post, :comment) %>').prepend('<%=j render( 'comments/form' ) %>');

That will expand to $('#comment_post_14').prepend('<form ... >'); which will inject the form into the top of the comment_post_N container.

Trouble is, it will also do that again and again if you click the link repeatedly. To get around that, you could put the link to add a comment inside the container you want to fill with the form, and then use the jQuery html() method to replace the contents. That would look the same as above, just replace prepend with html. This gets around you needing to test if the form is already there, because the moment you click the link, the link is replaced with the form and you can't click it again.

So you have something like this in the end:

<%= content_tag_for(:div, post) do %>
<%= simple_format post.content %>
<% unless post.attachment.blank? %>
<%= image_tag(post.attachment, height: 250) %><br>
<% end %>
<%= content_tag_for(:div, post, :new_comment) do %>
<%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
<% end %>
<%= content_tag_for(:div, post, :comments) do %>
<%= render post.comments %>
<% end %>
<% end %>

The new.js.erb becomes this:

$('#<%= dom_id(post, :new_comment) %>').html('<%=j render( 'comments/form' ) %>');

And then to update the page, you want to render just that post again into the list. This is why you wanted to have the posts/index.html.erb depend on a _post.html.erb partial to render the list -- you're automatically set up to do this last step.

Make sure that your form_for method includes the remote: true configuration pair. This will submit the form via Ajax.

In comments_controller.rb, make sure you have a respond_to block for :js in the #create method. In case of an error, it will need to render the :new method again, but if the save succeeds, it should just render the create.js.erb by default (pass an empty block to that content_for).

create.js.erb would be something like this:

$('#<%= dom_id(@comment.post) %>').replaceWith('<%=j render @comment.post %>');

And that's really it. If it doesn't work, it's probably a typo on my part.

Walter


>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3fea1525-2b10-4718-9fa0-b6d04216aa51%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0AB50A72-3E18-438D-8991-15CB478DEDC9%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails



On Sunday, June 18, 2017 at 11:30:27 PM UTC-4, Walter Lee Davis wrote:

> On Jun 18, 2017, at 8:24 PM, fugee ohu <fuge...@gmail.com> wrote:
>
>
>
> On Friday, June 16, 2017 at 6:47:49 PM UTC-4, Walter Lee Davis wrote:
> There can only be one instance of an ID on any given page. And nothing you did in this example will render the id #commentable. If you look at my example, I did not use an ID on each element. The selector in $('#commentable').each should be $('#parent_of_the_list div'), and you'll have to apply whatever ID you want to search for to a parent element of the commentables. If you want to do this in a slightly simpler manner, you could apply a classname to the commentables, using the div_for helper: <%= div_for(commentable, class: 'commentable') do %>. Then you can change the jQuery to $('.commentable') and that will also work.
>
> Walter
>
> > On Jun 16, 2017, at 4:14 PM, fugee ohu <fuge...@gmail.com> wrote:
> >
> > The anchor doesn't get rendered I didn't know what to use for the element name so I used the same as I used the same variable I passed to div_for in my view, commentable Thanks in advance
> >
> >
> > View:
> >  <%= div_for(commentable) do %>
> >  <% end %>
> >
> > js.erb
> > $(document).on('turbolinks:load', function(){
> >   $('#commentable').each(function(){
> >     var elm = $(this);
> >     elm.append('<a href="/comments/new?commentable_id=' + elm.attr('id').split('_')[1] + '">Comment</a>');
> >           });
> > });
> >
> >
>
>
>  Here's my page souce and js.erb it's not appening anything to the page with the render
>
> <div class="post">
>   <p>Doing nothing as usual</p>
>  
>
>   <a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>
> </div>
> <div class="post" id="post_14">
> </div>
>
> $(document).on('turbolinks:load', function(){
>   $('#post div').click.(function(){
>     var elm = $(this);
>     elm.append('<%= form_for @comment do |f| %>  <%= f.hidden_field :commentable_id, value: @comment.commentable_id %><%= f.hidden_field :commentable_type, value: @comment.commentable_type %>  <div class="field form-group">                <%= f.text_area :body, class: 'form-control' %>          </div>          <div class="field form-group">                <%= submit_tag "Post comment", class: 'btn btn-primary' %>          </div>        <% end %>');
>   });
> });
>  

You've skipped over the last set of instructions I sent you, and you really need to do this in order or it will never make sense. Show me the code you are using that loads the form into another page, and please don't post it unless it is working in a browser and you can save comments. Get that far, and THEN I will be happy to help you take it into Ajax land.

Walter

 _post.html.erb

<%= content_tag_for(:div, post) do %>
    <%= simple_format post.content %>
    <% unless post.attachment.blank? %>
      <%= image_tag(post.attachment, height: 250) %><br>
    <% end %>
    <%= link_to 'Comment', new_comment_path( 'comment[commentable_type]': 'Post', 'comment[commentable_id]': post.id), remote: true %>
    <%= content_tag_for(:div, post, :comment) do %>
    <% end %>
<% end %>

produces

<div class="post" id="post_13">  	<p>listening to blues</p>   	<a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=13&amp;comment%5Bcommentable_type%5D=Post">Comment</a>  	<div class="comment_post" id="comment_post_13">  </div></div><div class="post" id="post_14">  	<p>Doing nothing as usual</p>   	<a data-remote="true" href="/comments/new?comment%5Bcommentable_id%5D=14&amp;comment%5Bcommentable_type%5D=Post">Comment</a>  	<div class="comment_post" id="comment_post_14">  </div></div>

new.js.erb
$('#post comment div)click.(function(){

This doesn't produce anything


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3fea1525-2b10-4718-9fa0-b6d04216aa51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails Monday, June 19, 2017

Hi everyone,

I am happy to announce that Rails 4.2.9.rc2 has been released.

This is going to be the last bug fix release of the 4.2 series, so please test this release candidate.

If no regressions are found, expect the final release on Monday, June 26, 2017.
If you find one, please open an [issue on GitHub](https://github.com/rails/rails/issues/new)
and mention me (@rafaelfranca) on it, so that we can fix it before the final release.

## CHANGES since 4.2.8

To view the changes for each gem, please read the changelogs on GitHub:

* [Action Mailer CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/actionmailer/CHANGELOG.md)
* [Action Pack CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/actionpack/CHANGELOG.md)
* [Action View CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/actionview/CHANGELOG.md)
* [Active Job CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/activejob/CHANGELOG.md)
* [Active Model CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/activemodel/CHANGELOG.md)
* [Active Record CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/activerecord/CHANGELOG.md)
* [Active Support CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/activesupport/CHANGELOG.md)
* [Railties CHANGELOG](https://github.com/rails/rails/blob/v4.2.9.rc2/railties/CHANGELOG.md)

*Full listing*

To see the full list of changes, [check out all the commits on
GitHub](https://github.com/rails/rails/compare/v4.2.8...v4.2.9.rc2).

## SHA-256

If you'd like to verify that your gem is the same as the one I've uploaded,
please use these SHA-256 hashes.

Here are the checksums for 4.2.9.rc2:

```
$ shasum -a 256 *-4.2.9.rc2.gem
72037af7844a5b7c9da34d8f177ea5ddc02cc50746cf0f7a2423d9fdaf8daf79  actionmailer-4.2.9.rc2.gem
025ce2b5480da4ead138318256f525b233869f5d6dddd3532ab5eb9129da54ea  actionpack-4.2.9.rc2.gem
d000f1f891b3744000ae73bae8adfe97488b5cfb83929be0e02585e8ef5354bf  actionview-4.2.9.rc2.gem
5e894159ca0fdab9c1ff34626380431c84b1bd080132019ba3c9a42e2bf7ff97  activejob-4.2.9.rc2.gem
33d44145becef028f8d241c800cd049e9e0151111c4b2aca30b68f4eff1d8095  activemodel-4.2.9.rc2.gem
bdc035ad3ac9687af6897e532aae7b7a3111f7a6bf88444bd20746a1e3633970  activerecord-4.2.9.rc2.gem
c548e36f68ed575394559951de7d798a6e5d2da1c48a489ac40032ae3b667327  activesupport-4.2.9.rc2.gem
eb7cdb1b7bb1196ff40d74a98ec44d4521fe3c4e0f4226c814be41e8b1f17d6b  rails-4.2.9.rc2.gem
b939bbf06be8eb7b8a21fdb64c010a96aa4d23d9346f92b1a105f14bc994c112  railties-4.2.9.rc2.gem

```

As always, huge thanks to the many contributors who helped with this release.


Ruby on Rails

Hi everyone,

I am happy to announce that Rails 5.0.4 has been released.

## CHANGES since 5.0.3

To view the changes for each gem, please read the changelogs on GitHub:

* [Action Cable CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/actioncable/CHANGELOG.md)
* [Action Mailer CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/actionmailer/CHANGELOG.md)
* [Action Pack CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/actionpack/CHANGELOG.md)
* [Action View CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/actionview/CHANGELOG.md)
* [Active Job CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/activejob/CHANGELOG.md)
* [Active Model CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/activemodel/CHANGELOG.md)
* [Active Record CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/activerecord/CHANGELOG.md)
* [Active Support CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/activesupport/CHANGELOG.md)
* [Railties CHANGELOG](https://github.com/rails/rails/blob/v5.0.4/railties/CHANGELOG.md)

*Full listing*

To see the full list of changes, [check out all the commits on
GitHub](https://github.com/rails/rails/compare/v5.0.3...v5.0.4).

## SHA-256

If you'd like to verify that your gem is the same as the one I've uploaded,
please use these SHA-256 hashes.

Here are the checksums for 5.0.4:

```
$ shasum -a 256 *-5.0.4.gem
f296d82b6494bc6591963f2cd91a08f6853f3ce9b784ab8a6bada5588ceee280  actioncable-5.0.4.gem
31cb0ca3654c4b9423480fd5b43dec6740c3c234195b50c9906745587ed8c6cc  actionmailer-5.0.4.gem
22e48ed14a49ef76278fa249035aaf2fb1d8a9abc649444a2510a94ffba3d7e3  actionpack-5.0.4.gem
f5b53d280c894afd423be26ffc7546266fd6490c91f7e0e3c2dd6524d8d3dbcb  actionview-5.0.4.gem
65997364e723bf8b041172cb5562da08181d45bbed8d04d9516dc8b6672e1d7f  activejob-5.0.4.gem
6145ae036d43b5b19c91c1d8c8936d06b475f17bf8a255919ce4afb6015d7216  activemodel-5.0.4.gem
d82ba1b3519e50c509e0da488f224e5a6164633ebd3c00053e55ade49a8a3d6b  activerecord-5.0.4.gem
ec3af21ed8df9fdd20d9b9c9a8bef3fc3b7d8b69bcb15a7dbdf8f37072bf2c23  activesupport-5.0.4.gem
956e9bd0acf86701b139432eb3c9e6bc6d2f51e7cccec9a5dcf9c7d3cb14d87d  rails-5.0.4.gem
534fbe66df5f7a8c4e2926e7497a7b876f1d34e33b56238db29faf159ad778dc  railties-5.0.4.gem

```

As always, huge thanks to the many contributors who helped with this release.

Ruby on Rails

Also look at Mechanize, which I believe can do a headless JS scrape of a site. It's purely a scraper, so less likely to be so test-centric.

Walter

> On Jun 19, 2017, at 10:18 AM, Jason Fleetwood-Boldt <tech@datatravels.com> wrote:
>
>
>
> I think he's scraping someone else's site.
>
> You obviously can't do this with Ruby alone, as there is no headless web browser written entirely in Ruby (that's just nonsense)
>
> If you can get phantomjs working on your production site, that's probably the way to go. Look deep into the internals of Capybara to understand how it drives phantomjs. With phantomjs, you basically have a headless web browser and you can use Capybara's DSL to access parts of the page, including evaluating scripts and parsing the DOM.
>
> Just keep in mind phantomjs is an actual executable so it needs to be compiled and built for your production environment explicitly, which might be a little tricky depending on where your site is.
>
> But a little birdie told me a few months ago that the phantomjs team has decided that once Chrome has a headless mode, which I believe is forthcoming, they plan to abandon phantomjs in favor of Chrome's headless mode. Not sure if that's really true or when that will happen.
>
> -Jason
>
>
>
>> On Jun 18, 2017, at 8:36 AM, Colin Law <clanlaw@gmail.com> wrote:
>>
>> On 18 June 2017 at 12:21, Martin Luy <martin.luy@gmx.net> wrote:
>>> I'm extracting content from some websites. Currently I evaluate HTML code
>>> using Nokogiri. But the relevant content is not contained in the responded
>>> body of the HTTP GET request. This is because there is some Javascript code
>>> like $(window).load() or $(document).ready() that will send some Ajax
>>> requests and fill the original HTML code.
>>>
>>> So I'm searching for some library that automatically executes Javascript
>>> code and Ajax requests just like a normal browser.
>>
>> Understood. Don't think I can help I am afraid. Does the site not work
>> with js disabled in the browser?
>>
>> Colin
>>
>>>
>>> Martin
>>>
>>> Von meinem Samsung Gerät gesendet.
>>>
>>>
>>> -------- Ursprüngliche Nachricht --------
>>> Von: Colin Law <clanlaw@gmail.com>
>>> Datum: 18.06.17 09:42 (GMT+01:00)
>>> An: "Ruby on Rails: Talk" <rubyonrails-talk@googlegroups.com>
>>> Betreff: Re: [Rails] browser simulator independent of web framework
>>>
>>> On 17 June 2017 at 22:58, Martin L. <martin.luy@gmx.net> wrote:
>>>> Hi all,
>>>>
>>>> Is there any browser simulator that fulfills these requirements:
>>>>
>>>> - gem written in Ruby
>>>> - automatically performing Ajax and Javascript code (XSS is not an issue
>>>> in
>>>> my case)
>>>> - independent of the frameworks used by the website (Rails, JavaEE,
>>>> ASP.NET,
>>>> ...)
>>>> - only client-side
>>>> - no testing
>>>> - no browser dependency
>>>
>>> What do you mean 'no testing'? If not for testing then what is it for?
>>>
>>> Colin
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Ruby on Rails: Talk" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/rubyonrails-talk/H_YImOIzNNo/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> rubyonrails-talk+unsubscribe@googlegroups.com.
>>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvqHArcWpbZ5gsfCiPg0EF%3D4kD8QzZbC3KnicN58uAZ8A%40mail.gmail.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Ruby on Rails: Talk" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to rubyonrails-talk+unsubscribe@googlegroups.com.
>>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/rubyonrails-talk/smyckbsskql3om4h9odf01hm.1497784510166%40email.android.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsaS8DzC2o0%3DHkKt_%2BMvvzqutm0mSHUj5jf7CoKvnqJEg%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> ----
>
> Jason Fleetwood-Boldt
> tech@datatravels.com
> http://www.jasonfleetwoodboldt.com/writing
>
> If you'd like to reply by encrypted email you can find my public key on jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org)
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A0A534AE-3ECA-41F9-9170-432A98DD743D%40datatravels.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7E161DC2-A4E6-4A12-8C13-1FE180EE57CB%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Ruby on Rails

Correction: this referenced blog post is from 2012, not 2013





On Jun 19, 2017, at 10:13 AM, Jason Fleetwood-Boldt <tech@datatravels.com> wrote:


Not sure were you got all of this code from… were you following an example somewhere?

This appears to be way overcomplicated for your use case.

The definitive and nearly ubiqutious method for simple object caching (incidentally, the singular form is spelled "cache," as in a small hiding place. The word comes from the French, not to be confused with cachet, which also comes from French, and means "superior status" or "prestige") is from the DHH post from 2013…



Assuming your objects are ActiveResource objects, you automatically get cache_key defined for you.

All you need to do is wrap the expensive (processing/time-intensive) code in the caching mechanism

Rails.cache.fetch(@contact)
   // serialize or render the response data
end 


… that's it. As explained in DHH's post from 2013, cache_key on @contact automatically includes the timestamp of when the record was last updated. When you make a change to any field the update_at timestamp changes, and so does the cache key, invalidating all caches associated with that cache key.

All of the other code you have looks like you went down a caching rabbit hole that is unnecessary. (But learning the internals of the Rails caching mechanism is a good thing for your own edification!)

-Jason 




On Jun 18, 2017, at 2:51 AM, Arup Rakshit <tuka.08@gmail.com> wrote:

I have the below code:

class ContactsController < ApplicationController
 
  # ..

  def top_3
    cache_identifiers = { contact_1: 1, contact_2: 2, contact_3: 3 }
    cache_keys = cache_identifiers.keys
    cached_keys_with_values = Rails.cache.read_multi(*cache_keys)
    uncached_keys = cache_keys.map { |key| key unless cached_keys_with_values.has_key?(key) }.compact
    uncached_ids = uncached_keys.map { |key| cache_identifiers[key] }
    uncached_contacts = Contact.where(id: uncached_ids).to_a

    uncached_keys.zip(uncached_contacts).each do |key, value|
      Rails.cache.write(key, value)
    end

    @contacts = cache_keys.map do |key|
      cached_keys_with_values[key] || uncached_contacts.shift
    end
  end
end

I am using memcached as cache store. Now my question is how can I invalidate the cache when say any of the attributes(name, email) of the contact record changes.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/13256849-6db8-47f9-97e8-c51688d54ba7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

If you'd like to reply by encrypted email you can find my public key on jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6BC11AD8-3FCA-418B-A0D5-9EBD3438CE5F%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.

If you'd like to reply by encrypted email you can find my public key on jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org