Activity
Yo! What's happening is basically:
- Create the new quote
- After_save fires, attempts to schedule.
- If that fails, you update the record, causing the after save to run again
- If it doesn't fail, when the record does get published, you update the record, causing the after_save callback to fire once more
- This is going to obviously throw an error on Twitter, etc for duplicate posts at some point causing your code to update the record again that there was an error, fire the after_save callback and then attempt to post again.
My suggestion here would be actually to remove the after_save
callback and do this explicitly in your controller. You'll save yourself some trouble doing that. You can also set it up so that if it fails to publish, you can note the error, and schedule a job to attempt it again in the future if you would like.
So a couple things:
You're calling after_save which means that if you call update_attributes, it's going to try to publish again. You'll get an infinite loop of this publishing attempt basically. Probably not exactly what you want. This is the primary issue with callbacks.
What's the error message that you're receiving? It looks like you save this to the database, so I'm curious what's causing it to trip up.
I'm going to be doing some testing on Heroku to see, but I think you'll be fine using Puma on there still.
I forgot about that until after I finished recording! The actioncable-examples repository that I cloned still used the Redis adapter default, so I totally overlooked that change. Great to know.
Awesome, didn't realize they started offering that. This is going to help a lot with Twitter integrations. Thanks for sharing!
Posted in Rich text format editor in rails 4
The ghost editor looks pretty sweet too! Thanks for sharing that.
Posted in How to use devise with Adminitrate?
That definitely looks right. Huh. I'm not sure what is causing that.
One thing you could try is removing the Admin class and using AdminUser as the name instead to see if that does the trick.
Posted in How do I build conditional form fields?
For most of these, I've found that the easiest way (for me at least) is often to write some custom JS to handle it. Basically when the first thing is selected, use an AJAX request to load up some JSON for the desired subcategories and then use those to update the options available in the form. Something like this: https://kernelgarden.wordpress.com/2014/02/26/dynamic-select-boxes-in-rails-4/
I'll have do an episode on this soon, because this is a really common thing to do, but not well documented.
Posted in Sharing on social network
I've been pretty happy using #3 because it doesn't slow down the page load at all, and you can still customize those pretty well. The downside is you can't include the count of shares because that requires JS.
If you do need those extras from the JS, you could use a service to simplify, or a relatively easy way is just to include the JS libraries using the official instructions. I've found that using services like AddThis are really just a pain to use. Same thing goes for gems, it's just adding an unnecessary layer of abstraction to it that you don't really need.
I just updated my open graph tags tonight and did the following in the head in the layout.
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@gorails" />
<meta name="twitter:title" content="<%= yield :title %>" />
<meta name="twitter:description" content="<%= yield :meta_description %>" />
<meta name="twitter:image" content="<%= asset_url "open-graph.jpg" %>" />
<meta name="twitter:creator" content="@excid3" />
That way the views can have the following code to put in the yield sections.
<%= content_for :title, @episode.name %>
You can then wrap the head code with the following to include it or not based upon existence of the content:
<% if content_for?(:title) %>
<% end %>
I believe there's a "converters" option that you can pass in. It basically tries to convert every column to a Date object and if it is successful, it will use that. You'd pass in the ":date" option for it (something like converters: [:date] I believe). You can read a bit more about that here: http://ruby-doc.org/stdlib-...
Plus if you have something custom that doesn't work with that, you can write your own converter. I just did this for a project and figured I should make an episode on it. Pretty nifty and easy to do, but really poorly documented.
Ah that's disappointing. I wonder what the issue was with the JS...As long as you've got an easy admin to work with, that's all that matters.
Great question Jeff. I think Mongoid's docs do a pretty good job outlining the difference between it and ActiveRecord here: https://docs.mongodb.org/ec...
Posted in Rails Console
What Andrew said! For some of the controller methods, you can sometimes just instantiate the class like any other normal object. The trouble will be that you don't have request objects to work with to pass in.
That's a really good idea! I'll do that. :)
Computers eh? :)
Posted in Rich text format editor in rails 4
It's pretty much the most awesome one I've seen. I'm going to have to do an episode on it soon.
Posted in Rich text format editor in rails 4
If you don't need anything too complicated, Basecamp just released their new text editor that I found to be really good. It's called Trix. https://github.com/basecamp/trix
There's also CKEditor and TinyMCE that have been used by a lot of people in the past. I don't particularly like them, but they do a lot more than Trix.
I'm using ActiveAdmin for most sites since it existed beforehand, but now I'm starting to use Administrate in production. Only real concerns with this over production use is that it hasn't existed for all that long to work out the basic bugs. Since it's pretty much scaffolds, you can pretty easily debug anything that would go wrong. The main downside right now is going to be a potentially quickly changing API that may be more than you would want to deal with maintenance wise.
You can setup Refile to cache some file metadata like the filename to your model. https://github.com/refile/r...
That should take care of showing the filename and then anytime the URL is clicked, then that's when Refile will download the file. Just displaying the link won't cause it to download the file just to render the filename in the link.
Nope, that should still work out of the box. Server side will just continue to set cookies, but will only match users available for the current tenant.
That's because the sinatra app (which Refile is referring to) gets mounted to your Rails app at /attachments. Rails basically routes the URL over to the Sinatra app, effectively so that the files never hit your Rails code. It just gets diverted before Rails would start processing it. And then files are served up from the same url because that's where the Sinatra app is.