ruby-on-rails

Update two different parts of the page using unobtrusive JS (in Rails w/jQuery)

When the user clicks a sorting link on my blog, I want to use AJAX to both pull in new posts and update the sorting link section. This would be easy using RJS, but I want to keep my JS unobtrusive and respond to AJAX requests with only data (and no code). Here's what I'm doing now: $('a.order_by').livequery('click', function() { ...

Google Analytics Alternative for a Rails Application

I am working on a project using Ruby on Rails and I need to monitor web requests to generate traffic analytics (hits, unique visitors etc), but I have been instructed that using an external service, such as Google Analytics, is unacceptable (don't ask me why, I may break down and cry). I can however, use a plug in or anything else which...

In Rails, how do I access the Request.ServerVariables like you do in ASP?

I want to access a given Requests ServerVariables, but I can't seem to find anything on Google on how to get access to the Server Vars of the request object. How do I do this or am I doomed to simply never know? An example of why I'd want to do this (but not actually what I want to do): User logs in, and you want to store the IP addres...

How can I make rails helpers more object-oriented

I'd like to, for all helpers, across my entire Rails application, replace this syntax: time_ago_in_words(@from_time) with this: @from_time.time_ago_in_words Ideally this change would also make the helpers available anywhere in my application (the same way, say, 5.times is). Does anyone know of a plugin that does this? Would it be ...

Set path for original images using paperclip in Rails?

The situation I have a simple model with an attached image using paperclip, which has a couple of processed styles for it (thumbnail, full, feature). At this point it works as it should, and makes a directory structure for each object in /public/assets/foo/, containing subdirectories for original, thumbnail, full, and feature. The prob...

Should the extensive use of local_assigns.has_key? in partial be considered a code smell?

I have the Rails partial which has a few such checks: <%= if local_assigns.has_key?(:show_blabla) && show_blabla == false %> blabla <% end %> I think that sort of hides the real list of parameters which are used by such partial, and hey local_assigns is not in documentation even. What are your thoughts? ...

render default template when requested template is missing in Rails

For a plugin I want to hack the following feature into Rails: When a (partial) template does not exist (regardless of the format) I want to render a default template. So say I call an action 'users/index' if users/index.html.erb does not (or other format) exist, 'default/index.html.erb' should be rendered. Similarly, If I call an act...

How do I know when to and whether to have a separate controller for a piece of code?

So I am in a situation where I have to decide whether or not to have a separate controller for a particular piece of code. We have a home page that acts like a hub for the rest of the site. The page is accessible to all users (logged in as well as non-logged-in). I was thinking about having home as a separate controller and an action cal...

Deploy from Git using Capistrano without a hard reset?

I've an issue at the moment where we are running a CMS within a site (browsercms) that lets the user upload files. However, every time I do a deploy Capistrano runs a hard reset thus nuking any uploaded files. Does anyone have any suggestions as to how to prevent the hard reset, and just do a pull, or a way of moving the uploaded files...

Ubuntu: "Could not find rails locally or in a repository"

I'm following these instructions to set up Ruby on Rails on my Ubuntu machine. For now at least, I'm planning to use Mongrel. When I get to this step: sudo gem install rails ...I get this message: Bulk updating Gem source index for: http://gems.rubyforge.org/ ERROR: could not find rails locally or in a repository What should I do...

Partials in Liquid

Hello, We're trying to rewrite our current views from ERb to Liquid and we got following problem: we have a lot of render(:partial => '/path/to/partial') in our code, but we found absolutely no instructions how to render partials in Liquid. The only one solution we found was with help of render_to_string but it's just to ugly to be true...

Slow initial server startup when using Phusion Passenger and Rails

To jump on the band-wagon of Phusion Passenger we've setup a staging server for a small rails app to test things out. So far it has been very nice to use, it makes installing/configuring and deploying apps a breeze. The problem is the site we're using doesn't get hit very often and it seems to shut down the servers in the background. Me...

Is developer productivity higher on Ruby on Rails or Grails?

Given that both Ruby on Rails (RoR) and Grails can run on the JVM (Java Virtual Machine), which language and framework enables equally competent and experienced developers to be more productive and roughly by what percentage? (i.e., deliver more business functionaity for the same amount of effort) I know that Grails is easier for a Java...

RAILS_ENV and rails 2.3.2

Hi, i noted that in rails 2.3.2 there is no more option to set which rails environment you are using. So i cannot just set it anymore in environment.rb? There is any other way to set it? ...

How do I add extra data to ActiveRecord records being serialized to JSON in Rails?

I'm exposing some resources via a simple API that returns JSON. I would like to inject the path to each of the resources so that the consumer need not construct them. Example of desired output for something like User.all.to_json: users: [ {user: { id: 1, name: 'Zaphod', url: 'http://domain.com/users/1.json' }}, {user...

Nicer alternative to the default Rails scaffolding stylesheet: scaffold.css?

I'm looking for a more attractive alternative to the standard scaffold.css? Has anyone come across a stylesheet that was specifically designed as a more attractive, less sparse alternative to the built-in scaffold.css? ...

Rails & restful_authentication woes with Internet Explorer (all versions)

I have a rails application deployed that works fine in Safari, Firefox, and Opera. However, when I try and login from Internet Explorer 6+, I get taken to the correct page but nothing shows up. The source says everything is there, but the page is just blank. When I hit refresh everything works normally. Anyone have experience with this? ...

Process many incoming emails in Rails: MySQL vs. Imap / Pop3 vs. other solution

Hi, at an application I'm working on users can forward their email-accounts to an address from our system (something like [email protected] ). It doesn't matter here why they should do this, but I need some professional advice on the best way to approach this. The basic idea is that our mailserver receives the incoming (for...

RJS method outputting raw javascript

I've got a page where I'm dynamically adding elements to a from a series of select boxes. I'm using RJS to do this and it's working great. Now, these elements in the div are a series of that are accompanied by Delete buttons, in case the user wants to remove a textarea. Here's where I'm hitting a wall. Here's the code that runs the De...

Randomly long DB queries/Memcache fetches in production env

I'm having trouble diagnosing a problem I'm having on my ubuntu scalr/ec2 production environment. The trouble is apparently randomly, database queries and/or memcache queries will take MUCH longer than they should. I've seen a simple select statement take 130ms or a Memcache fetch take 65ms! It can happen a handful of times per request,...