Rails Ajaxy File Upload - ruby-on-rails

Is there a defacto way of doing an Ajaxy file upload in Rails? (I say "Ajaxy" because it can't really use XHR).
I've read about various approaches and plugins. Wondering what's the cleanest/most approved of by the community.
Thanks!

SWFUpload is a common tool for Ajaxy uploads.
Here are a couple links that should integration with Rails.
http://blog.airbladesoftware.com/2007/8/8/uploading-files-with-swfupload
http://thewebfellas.com/blog/2008/12/22/flash-uploaders-rails-cookie-based-sessions-and-csrf-rack-middleware-to-the-rescue

If you dont want the uploader bases on flash, you can check http://blueimp.github.com/jQuery-File-Upload/ its pretty cool.

I've used responds_to_parent with success on several projects.
The idea is that you're doing a full POST to an iframe embedded on the page. The responds_to_parent plugin adds some helpful functionality to then execute success or failure javascript in the context of the main page.

I've had a good time with Plupload. There is a plupload-rails gem (I don't trust the plupload-rails3, it's too automated, but might be fine). It offers several runtimes (html5,html4,flash,silverlight,gears,...) and they can be setup as fallbacks for each other, so you can support all clients no matter if they have silverlight or flash or even if they use internet explorer.
jQuery-File-Upload looked nice, and I almost used it in mu last project, but I had a very hard time getting it to play nicely with Internet Explorer. (I was also using Amazon S3, which complicated things)
I just saw the date, I hope new comers find this useful.

Related

Rails video embedding gem, service

Hi there i've had a look around for some video embedding tools i can use for my site, i'm looking at letting user embed video into a site through their profile, i've got the images down with paperclip, i was lo
oking at embedly looked good but the implementation of it looked a little complex for me, any suggestions would be great, thanks.
I've used http://sproutvideo.com/ in the past. Worked as expected, although it's not free. Couldn't use a free service without breaking agreements and such for that project.

What's the best approach to handling multiple file uploads in rails?

I'm trying to attach multiple files to a comment model (currently with a has_many :attachments) using paperclip. It seems to be quite a lot of work and a bit fiddly for something that should be trivial. What's the modern rails way of doing this, with scalability and security taken into account?
I'd recommend using jQuery File Upload. It's compatible with all browsers and doesn't require any flash or whatever: only javascript.
Look in the wiki, there are tutorials. I made one for v3 and v4, and someone did the one for the latest version.

Is there a Ruby on Rails site thumbnail generator available?

I'm hoping to avoid building this if it already exists. Does anyone know of a plugin for Ruby on Rails that will generate a screenshot of a web site? Thanks in advance to anyone who can help me find one.
As far as I am aware you need a server with a desktop (eg. Gnome, X11, KDE) and a web browser with thumbnail capabilities installed (eg. webkit and CutyCapt). Of course this is not usual for a Linux server.
I have used the service suggested by Soufiane using code based on Peter Coopers snippet and it works very well.
Generating website thumbnails would require significant server resources and some sort of background process and job queue so using a web thumbnail generation service might be a better alternative to generating your own.
Yes there is a wonderful solution:
http://webthumb.bluga.net/
It has an great API and there are some Ruby Wrappers (i.e. http://github.com/simplificator/rwebthumb)
It allows you to process 100 thumbnails a month, if you need more the price for credits is very generous if you ask me.
This is not a plugin, but I found this snippet which is using an external site to do what you want (I think.). I didn't test it though.
This is getting a little dated now, but just for posterity's sake there is an answer over here

Best plugin for creating a "friends" system/social network for latest Rails?

I'm looking for a Rails plugin that eases the development of a "friends" system or social networking system for the latest versions of Ruby on Rails.
Before anyone says it...I know, I should probably create it myself, from scratch. And I am fully capable of this (I think). I'm just looking for a good plugin that can a.) make life a bit easier for me and b.) give me some ideas for reference.
I tried to make my own authentication system, and did what I thought was okay, but then I switched to restful_authentication and realized how poor my system was in comparison.
Thanks in advance...
U might wanna try Community Engine
from the website
CommunityEngine is a free, open-source
social network plugin for Ruby on
Rails applications. Drop it into your
new or existing application, and
you’ll instantly have all the features
of a basic community site.
it uses engines, easy to change layouts or do modifications
real world example - http://www.weebabystuff.com/
another option I know is Insoshi as Chuck posted
updated : look at this blogpost http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/
-- Ed :) --
You could look into http://lovdbyless.com/
This is a free open-source Rails social networking app which should give you plenty of ideas and pointers.
Ronald
You HAVE to see this railscasts video.
try acts_as_network plugin
The only one I know of is Insoshi. I haven't used it myself, but it sounds like that's what you're looking for.
I would recommend using OpenID library for rails to handle authentication.
On top of what others have said, there's also acts_as_network. The bonus of this one is that it's a pure plugin (doesn't require engines). Not having to worry about engines is a huge plus. The downside, of course, is that it's not a full fledged social network. It's just a friending plugin for models.
You might want to checkout the Amistad gem. It looks pretty simple and it supports both Mongoid and Active Record.
For avatars i would use avatar and try will-paginate for pagination. other then that i love can_serach to make it alot easier to search in the database.
You should also look at the other gems by technoweenie. There is alot of great stuff there that can help you
I've just been researching this myself and chosen to go with Bort & CommunityEngine
Bort because I am familiar with it already and it provides all you need in user authentication and basic application functionality. Community Engine because it is an Engines based plugin and some aspects of Engines are being merged into Rails 2.3 so I know what I learn will continue to be useful and because CommunityEngine seems more modular while lovedbyess and Insoshi seem more like complete applications and I suspect it would likely be more work to disentangle the features I want from the ones I don't. However, take that with a huge grain of salt since it is just based on high-level quick browse initial impressions.
If you just want an activity feed then there is the activity streams plugin

The dangers of using ExtJS on a big project with RoR?

We are developing a considerably big application using Ruby on Rails framework (CRM system) and are considering to rewrite it to use ExtJS so that Rails would just do the data handling, while ExtJS would do all the browser heavylifting in a desktop-like manner.
Anyone has some experience and hints about what would be the best approach? Is ExtJS mature enough to be used in relatively big (and complex) applications? And what about the Rails part - what would be the best approach here?
EDIT:
Just to make it clear. I would prefer to do it in such a way that all the javascript client side application code is loaded at once (at the start up of the application, optimally as one compressed js file) and then just use ajax to send data to and from Rails app. Also, it would be nice to have ERB available for dynamic generation of the Ext apliccation elements.
I currently have an extremely large, desktop style app written in ExtJS. It used to run on top of Perl's Catalyst MVC framework, but once the entire View layer was converted to an ExtJS based desktop I started migrating to Ruby on Rails models and controllers. It is equally as fast, if not faster, and easier to maintain and has a much smaller code base.
Make sure that you set your active record config to not include the root name of the model in the json, so that Ext's JsonStore has no problem reading the records. There is an option on ActiveRecord BASE called include_root_in_json you have to set to false.
Make sure that you properly define your Application classes in Ext and maximize code re-use and you are going to want some sort of method to clean up unused nodes in the DOM. Javascript performance can be a real pain unless you are using the latest versions of Safari or Firefox 3.1.
You probably will want some sort of caching method for data on the server to be served to your application in JSON format at the time the page is loaded. This will cut down on the number of round trips via Ajax.
Definitely make use of Ext's WindowManager and StoreManager objects, or roll your own from Ext.util.MixedCollection
Develop your code in separate, managable files, then have a build process which combines them into a single file, and then run YUI's compressor or Dean Edwards Packer on it to compress / obfuscate the file. Serve all JS and CSS in their own single files, including the Ext supplied ones.
[2012 update] ExtJS was acquired by Sencha, who offer a GPLv3 license, and two commercial licenses.
[2008-Oct comment] ExtJS is great on technical merits, but the fiasco with the licensing several months ago have led me to look at other frameworks - I don't trust the creators of ExtJS at all now. I don't like how they worded their license, and how they pretended to be open source advocates whilst obviously attempting to profit unfairly off those who believed them.
I'm only against using ExtJS on moral grounds.
This belongs in answer to Milan's comment on my previous answer, but as a newcomer here I don't have enough reputation points to reply there:
There was a problem with the "sp is undefined", which was a result of Rails' caching of the JavaScript files into one large file (there would be several hundred files otherwise). The caching introduced some weird bugs with newlines which threw the whole thing off. This had me pulling my hair out for a while, but the solution was to update Ruby from 1.8.6 (patch level 72) to the latest 1.8.7. This fixed the problem so please check it again if you want to have a look (you'll need to do a full refresh to beat the asset caching).
I'm glad you've come across the Ext MVC stuff before. At present I can fully believe it must be quite difficult to understand, mainly due to a lack of examples, tutorials and demos. The code itself is reasonably well documented however (at least the newer code anyway, there is a lot which needs clearing out).
I am currently in the process of refactoring a few key classes before it is ready for a proper 'release'. When that's ready (I'm thinking a couple of weeks), I will generate the documentation and set up a quick site with some demos and example code. When I've done so I'll put up a post on my blog (http://edspencer.net).
My aim with this is to try to provide a framework which will make writing this type of application much simpler, and to establish some conventions. Currently there is no consensus or default way of structuring ExtJS applications, so anything we can do to move that along will be a step in the right direction! Comments and contributions are more than welcome.
I've successfully deployed a large RoR/ExtJS app of the kind you describe ("single-page" client-side AJAX driven). Ext_scaffold is pretty much a red-herring.
It's not too taxing to get RoR and ExtJS working smoothly together. The fundamental choice is whether to extend ExtJS to "speak Rails", patch RoR to "speak ExtJS", or meet in the middle. It's going to depend where your team's skills are.
I adopted the meet-in-the-middle strategy, which includes:
Extend Ext.data.Store and Ext.data.Record to be aware of Rails routing conventions
Hack Ext.grid.EditorPanel and Ext.form.BasicForm to play well with ActiveRecord associations
Write some modules to extend ActiveRecord::Base and ApplicationController to simply commits from Ext.grid.EditorPanel and Ext.form.BasicForm
That's pretty much it.
Having said that, there are drawbacks to ExtJS.
You're going to have to get your hands dirty in the internals. Don't be beguiled by the demos.
The community documentation is poor and PHP-centric.
Coming from the Github/Lighthouse-centred RoR world, using VBulletin is like waking up in 1998. I mean, there's no public bugtracker just a forum post that's updated (WTF?).
The code is a bit over-engineered.
The team have lost Open Source credibility so they've lost Open Source oxygen.
The team appear to be focused integration with GWT (can anyone say "enterpri$ey"?).
You might want to have a look at the Netzke framework that is thought to do just that: facilitate creating complex one-page web-application with the emphasis on modular approach.
The advantages of Netzke are:
Reusability and extensibility of the code. Once you get your component (both client and server side) made, you can reuse it in any place, combine with other components, or event extend it with inheritance.
Efficiency. Class for every component is loaded from the server (and evaluated) only once, which saves a lot of time on server-client communication.
It's open source, and it's in active development. It has live demos and example code.
It has prebuilt components that you can use straight away without even touching Ext JS (just configure them in Rails)
It's been used (by its author) for real-life development of a complex logistics application.
Disadvantages of Netzke are:
The code is still young, and the community small.
If you're interested, have a look at the description and design details here: https://github.com/nomadcoder/netzke-core
Live demo/tutorials can be found here: http://netzke-demo.herokuapp.com and here: http://yanit.heroku.com
Ext is definitely mature enough to handle this situation. I'm currently working on a Rails project with a lot of Ext, and the hardest part has definitely been working with Rails's to_json to render JSON that Ext can read (for arrays, hashes, models, which failed validation, etc.)
Check out the ext_scaffold plugin for Rails. I started with this and hacked away at its ActiveRecord/ActionView extensions until it did what I needed it to do.
I has some experience using ExtJS with Rails too. Using the framework is a great way to get some nice looking widgets for free. REST convention should sit well with the framework too if you use it to develop single page applications. Works well with RJS too.
Here are my gripes with using the framework
You can't really make use of flash[:notice] since reloading a single page application is silly. This makes passing validation notices and messages a chore since you have to use RJS/ javascript methods to show them.
You can't use erb much thus you have to encapsulate a lot of the logic into the json callbacks.
I've deployed ExtJS and Rails for a number of applications and they certainly can be made to talk to each other. We've put together a quick demo of an app we're currently developing in Rails + Ext at http://demo.domine.co.uk/admin. Ignore the front end for now as it's not complete - the admin section is essentially finished and you can log in to it with:
username: edward
password: rarrar
As the demo's not completely finished yet I won't guarantee that it works correctly in anything other than Firefox at this stage. There's no reason for it not to work in other browsers, I just haven't spent any time testing them yet. The point is more about the integration with rails though.
Every application on the start menu is interacting with the Rails backend via JSON. I've written a basic Rails plugin to do most of the work for us there. I'll be releasing the code behind that shortly but for now hopefully that gives some idea of how well these two technologies can work together...
While I have no experience of ExtJS (besides reading about in the "Practical Rails Projects" book) I used a jQuery Flexigrid with jrails to get more of a desktop feel.
That worked pretty well.
Ok. I use extjs gxt gwt on many project, and it very easy for develop. But I want to tell you that I built my project with extjs+gwt (gxt), I don't sure about Ruby.
link text

Resources