RailsCasts Pro episodes are now free!

Learn more or hide this

Nico Ritsche's Profile

GitHub User: ncri

Site: railstoolkit.com

Comments by Nico Ritsche

Avatar

Would have liked to see this cast for Test::Unit too... ;-)

Avatar

Yep, but what if track_activity fails? That's what Steve means I believe.

Avatar

Typo in rack middleware?

appication/json

Avatar

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.

Avatar

He might simply have not known about it. ;-) I didn't either, so thanx for the tip.

Avatar

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.

Avatar

Any hints on why not to use dom ready? Links?

Avatar

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.

Avatar

+1, thought so too (somebody mentioned it higher up in the comments already though).

Avatar

In case anyone is interested: I just released a gem for "ajaxifying" a rails app: https://github.com/ncri/ajaxify_rails

Avatar

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.

Avatar

Ryan used Ruby 1.9 hash syntax, that's why. You seem to be on Ruby 1.8x?

Avatar

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. ;-)

Avatar

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.

Avatar

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. ;-)

Avatar

I prefer using an ide debugger, like the one in RubyMine. You can conveniently step through code and inspect variables. Super useful...

Avatar

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.

Avatar

Ryan says in the end of the cast that Meteor is "only" for rich client side applications he is not normally working on. It appears to me though the trend for ALL web apps is currently exactly going towards that direction. Towards more interactive, javascript rich and snappy websites. As it is stated on the DerbyJS website: why not having realtime data push updates as a default on all websites if it is possible? To me it seems frameworks like Meteor and Derby are the future of web development. They also significantly improve the development experience by making browser reloads unnecessary. Opinions? I'd love to hear what others think. Especially, are there any use cases where "traditional" server side heavy frameworks like Rails are fundamentally working better than those new type of frameworks?

Avatar

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.

Avatar

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.

Avatar

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.

Avatar

I doubt heroku doesn't know about this possibility... ;-)

Avatar

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.

Avatar

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.

Avatar

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?

Avatar

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.

Avatar

What has SEO to do with server location?

Avatar

I prefer Heroku, so I can focus on development not setting up and maintaining servers. ;-)

Avatar

Ah, okay, so I guess we can just wait for Rails 4 with fully integrated default minitest support and switch then ;-)

Avatar

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?

Avatar

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...

Avatar

Post is by DHH, the name you mention is from a comment. ;-)

Avatar

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..

Avatar

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

Avatar

Well, one way is caching the whole page and loading user specific info like the logged in as box via ajax.

Avatar

Had to add the psych gem to my gemfile to get rails 3.2 working with one of my apps for some reason...

Avatar

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?

Avatar

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... ;-)

Avatar

A, thx, cool. a bit hidden though :)

Avatar

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.

Avatar

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.

Avatar

Well, a benefit of the asset pipeline is md5 fingerprinting of the images...

Avatar

Use the rails-dev-tweaks gem and you have your speed back. ;-)

Avatar

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."

From: http://devcenter.heroku.com/articles/read-only-filesystem#cedar

Avatar

Oh works now, had to restart the server after putting something in vendor. It's probably the same with the lib folder.

Avatar

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.

Avatar

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
=> nil

Avatar

Engines look promising in Rails 3.1!

Wondering why you didn't use something like

ruby
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.

Avatar

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 <%= %>.

Avatar

@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...

Avatar

@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...

Avatar

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.

Avatar

Wondering how to secure which channels people can listen to. As far as I understand, in theory anybody can listen to your messages through javascript in this example.

Avatar

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.

Avatar

@user 858: You could try uploadify: http://www.uploadify.com/

Avatar

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.

Avatar

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

Avatar

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.

Avatar

Erm, Antony, Prototype used to be the default rails js library. Many used it and I guess still many do... ;-)

Avatar

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

Avatar

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.

Avatar

I posted about this as well here a while ago: http://www.railstoolkit.com/posts/html-5-ajax-history-and-adress-bar-integration