Please read for an updated status on RailsCasts:
Learn more or hide this
GitHub User: ncri
Would have liked to see this cast for Test::Unit too... ;-)
Yep, but what if track_activity fails? That's what Steve means I believe.
You can also check out my nested form fields gem: https://github.com/ncri/nested_form_fields
Typo in rack middleware?
Yep, in this case I'd have done it exactly like you. In some cases you want to plug in variables server side. For those cases rails templates are useful.
He might simply have not known about it. ;-) I didn't either, so thanx for the tip.
In most cases turbolinks is actually slower than manually loading content with ajax, as it loads the whole body, which is not necessary in many cases for many sites.
I made a gem ajaxify_rails (https://github.com/ncri/ajaxify_rails), which only ajaxifies the main content area. We use it in a large site, in fact it has been extracted from it. It has a fallback for IE, unless pjax and turbolinks. Happy to hear feedback.
Any hints on why not to use dom ready? Links?
Seeing how to writing a plugin is nice, sure, but its just not the best solution here imo. Using "on", you don't need to worry about adding any event handlers later.
+1, thought so too (somebody mentioned it higher up in the comments already though).
In case anyone is interested: I just released a gem for "ajaxifying" a rails app: https://github.com/ncri/ajaxify_rails
Great screencast. I made an example app that uses http://blueimp.github.com/jQuery-File-Upload/ to upload straight to S3. It was using a rather complex iframe trick to get around Amazons same origin policy. That was before Amazon introduced CORS, now my app is basically obsolete... ;-)
Ryan, will you make a gem from the multifile uploader you showed in the end? I think that'd be a great idea.
Ryan used Ruby 1.9 hash syntax, that's why. You seem to be on Ruby 1.8x?
Would be cool to abstract the PermittedParams class even more, so that it's methods are not tied to one model only. It might be even cool to have a CanCan like gem for attributes to more easily specify permissions - or combine this with CanCan. ;-)
Cancan works on a more coarse level than this. It grants/denies access to entire actions and also loads instance variables. So this can be used in addition, it doesn't replace CanCan.
Nothing wrong with this approach I think. Changing rails code is perfectly fine, though documented if necessary, I'd say. Nothing wrong with extending/improving rails itself. ;-)
I prefer using an ide debugger, like the one in RubyMine. You can conveniently step through code and inspect variables. Super useful...
I have started playing with meteor. Developing is very smooth and fun. I get this "it just works" feeling, although there is still a lot missing in meteor. ;-) Actually I started first with derby as well, as it was also more appealing to me, however, I couldn't even get the examples to work. And reading the issues I found I'm not the only one.
Actually I just read that you can use npm modules: http://stackoverflow.com/questions/10165978/how-do-we-or-can-we-use-node-modules-via-npm-with-meteor
So no lock in after all?
There is also derby, a very similar framework with somewhat different philosophies. A Railscast on that also comparing it to Meteor would be great. From what I read, derby seems to be more flexible and less "lockin" then meteor.
I just made a gem for dynamically adding has_many association fields, similar to ryan's nested form gem: https://github.com/ncri/nested_form_fields
It allows arbitrarily deep nesting. You are welcome to play with it and send me feedback.
You could check if the model exists for the current locale (I think there is a method for that - would have to look it up) and if not redirect to the existing locale. Or add a text in that case saying something like "This Article doesn't exist in your language". And then you could link to all available language versions of that article. Clicking on one of the links, will change the app to the selected locale. That is also better in terms of usability compared to fallbacks, as it's not nice to have for example a russian article appear within a layout with english texts.
I doubt heroku doesn't know about this possibility... ;-)
There is a simple fix for this: Just use a pinging service that pings the site every minute or so. I do this with new relic. And voila, your app doesn't fall asleep anymore.
Okay, good to know. I hope that server location will lose SEO significance. No idea why it keeps having influence these days. Wonder what's the reasoning behind it.
I doubt that the server IP has much influence on search engine rankings these days. But I'm curious: does anyone have experience with this? Done some tests?
You can do a whole lot with a single dyno - and that is for free.
One dyno can serve one request at a time, that is for example 10 100ms requests/sec.
See here for more info: http://devcenter.heroku.com/articles/dynos.
You can also send mails from that one dyno, unless you send bulk mails. I recommend sending those in a background process to not block your web dyno(s). Also note that dynos drop requests that are longer than 30 secs.
A permanently running background process needs at least 1 extra dyno which is 35$/month. But if you don't need a permanent process you can programatically start a dyno when a job is added to the job queue and stop it once it's finished. That way you keep cost low, as dynos are paid per hour.
For image processing I recommend storing the images on Amazon S3 which is rather cheap, check their pricing info for details. Heroku is not suitable for storing files, as dynos are not persisted so you'd loose all uploads after dyno restarts or deploys.
Hope this helps.
What has SEO to do with server location?
I prefer Heroku, so I can focus on development not setting up and maintaining servers. ;-)
Ah, okay, so I guess we can just wait for Rails 4 with fully integrated default minitest support and switch then ;-)
So there is basically no need to setup all the extra classes, one can just use the rails internal stuff, including the test rake tasks...
@Ryan, is there a reason you created everything from scratch?
Or is it that when adding the minitest gem one has to do that to avoid using the ruby internal minitest?
Hm, actually when I create a new rails app it uses minitest automatically with ruby 1.9.
At least I see the seed option in my test output...
Post is by DHH, the name you mention is from a comment. ;-)
You can do a lot with noscript tags and to make sure pages behind js links are crawled, you can include their urls in a sitemap and submit it to google, etc..
I'm wondering why the cache sweepers are tied to the controller.
Some time ago I was writing about this here: http://www.railstoolkit.com/posts/rails-cache-sweeper-confusion
Well, one way is caching the whole page and loading user specific info like the logged in as box via ajax.
Had to add the psych gem to my gemfile to get rails 3.2 working with one of my apps for some reason...
Looks pretty good! ;-)
Anyone tried running a Faye server on Heroku's cedar stack?
How about security, how easy/difficult is it for an unauthorized client to subscribe to a private channel?
How else would you do it? Hardcoding to .id and a fixed attribute name? record_id is the function name to call to get the id, it could be :id, but also any other function like :permalink for example. attribute needs to be flexible too, otherwise you could use this builder only for one fixed named attribute. Not very practical I guess... ;-)
A, thx, cool. a bit hidden though :)
Thanks for the cast! Looks great. Is it possible to edit the source html directly? That would be a must have for me to use Mercury Editor.
Looks good, but: this always renders the full layout? That does seem very wasteful to me. But I guess its a tradeoff between code complexity and performance.
Well, a benefit of the asset pipeline is md5 fingerprinting of the images...
Use the rails-dev-tweaks gem and you have your speed back. ;-)
Heroku precompiles assets for you during push, in the cedar stack. However, it is broken for 3.1 rc6, They are working on fixing it.
About the read only file system:
"Cedar offers an ephemeral writeable filesystem. You can write out to disk anywhere you would like. Your changes will be lost on dyno restart and spin-up."
Oh works now, had to restart the server after putting something in vendor. It's probably the same with the lib folder.
oops, thx, that works! ;-)
However vendor/assets and lib/assets are not included...
I tried putting something in vendor assets, but it didn't work.
Rails.application.config.assets.path returns nil for me...
Loading development environment (Rails 3.1.0.rc5)
ruby-1.9.2-p0 > Rails.application.config.assets.path
Engines look promising in Rails 3.1!
Wondering why you didn't use something like
rescue_from Exception, :with => :record_error
in the application controller. Is it so that the error is raised like it normally is?
In that case you could reraise it in record_error I think.
Well, yeah, peoples opinions vary about haml. In the beginning i needed to get used to it too, but now it so much easier code views than it is with html + erb. By far the biggest benefits to me are not having to close tags, and not having to use the messy <%= %>.
@Nicolas: Well, its pretty simple, its nicer and cleaner to use... And you really don't have to use it if you don't want to. Well, and yes, there are choices made by the core rails developers... But Rails is an open project afaik, so you can contribute to those choices if you want. And if you don, fine, but then you might need to find some other tools to use if Rails doesn't suit you...
@Dmitri: JS is not bad at all, no, Coffe Script just makes it easier to write js code. I like it. Same goes for me with html and haml. I stopped using html in favour of haml, as its just cleaner and easier to write.
Ryan, it says 3 Comments, but there are 4 already...
Great Cast and Plugin! One little thing: I don't think the confirm password message is so useful. It should appear on the confirm field, not on the password field. But that's not really an issue with the gem but with rails.
@James: Thanks, sounds good!
Nice solution! You can also make a webinterface to modify the yaml files with the translations. That way you don't need to switch to another backend.
@user 858: You could try uploadify: http://www.uploadify.com/
Yep, I second that Allen, being able to change the page parameter's name is actually a crucial capability to me that is missing. I need it again and again, so I don't think its so uncommon. But I doubt it is difficult to change Kaminari to support this.
Yuval Tobias and others interested in multiple fileupload to s3 with progress bar: check out my fancyupload based S3 uploader: http://www.railstoolkit.com/posts/rails-amazon-s3-uploader-with-progress-bar-2010-update
Quite nice, indeed! I also prefer doing authentication myself. I ended up using devise though, as it takes care of a lot of details, like validation and has a lot of useful modules - also for OmniAuth.
Erm, Antony, Prototype used to be the default rails js library. Many used it and I guess still many do... ;-)
Rupert, check my blog post i mentioned in an earlier comment for a way to fix the problem with the missing state for the initial page load: http://www.railstoolkit.com/posts/html-5-ajax-history-and-adress-bar-integration
Does the back button in this example also work to get back all the way to the initial non-ajax load of the page? I had to add the state for the initial page load after the first ajax call using the replaceState function to get it working. See my blog post mentioned in my previous comment for details.
I posted about this as well here a while ago: http://www.railstoolkit.com/posts/html-5-ajax-history-and-adress-bar-integration