ruby-on-rails

RoR: Securing a Closed API

I have two rails apps on separate virtual servers, but in the same facility. Both apps can communicate via local ip addresses. This is a two part question: 1) How do I check where the request is originating and limit requests only to those from that location? 2) Do you think this would be secure enough? My gut is telling me this...

Error trying to get my first Rails application running.

I have a book called "Learning Ruby" and under the section for rails is gives a step-by-step walk through of creating a simple Rails web app. It says near the end type the command: ./script/generate scaffold addressbook addressbook But part-way through I get the error: wrong number of arguments (1 for 2) I assume this is be...

Problems with Routing Resources

I am setting up a Rails site using map.resources and map.resource, and I am encountering a limitation (as far as I know at least). Here is my current routing. map.with_options :conditions => { :subdomain => true } do |sub| sub.root :controller => 'company' sub.resource :company do |company| company.resources :clients, :path_pr...

Natural language date parser for ruby/rails

Does anybody know of something similar to Date.js in Ruby? Something that would be able to return a date object from something like: "two weeks from today". The Remember the Milk webapp incorporates this feature into their system and it is incredibly easy to use. I would use the Date.js library itself but because it is on the client sid...

Using ActiveRecord, is there a way to get the old values of a record during after_update

Hey everyone, Setup using a simple example: I've got 1 table (Totals) that holds the sum of the 'amount' column of each record in a second table (Things). When a thing.amount gets updated, I'd like to simply add the difference between the old value and the new value to total.sum. Right now I'm subtracting self.amount during 'before_up...

Rails Menus

I would like to know if there is a good plugin for rendering navigation links in Rails. It would be nice if it could render links to all possible GET actions on a controller directly from the routes file. ...

How to debug an issue of cron's not executing a given script -- or other?

I have a Rails script that I would like to run daily. I know there are many approaches, and that a cron'd script/runner approach is frowned upon by some, but it seems to meet my needs. However, my script is not getting executed as scheduled. My application lives at /data/myapp/current, and the script is in script/myscript.rb. I can r...

Need user to be able to download 2 files consecutively in a ruby on rails app

What is the best way to handle the need to a user to download 2 files. I'm using *send_data* to send the file to the browser. How can I allow the user to get two dynamically generated files from one request, OR what is a better alternative to do this. A simple example of what I'm trying to do is: def data_out output = "foo foo foo...

Ruby on Rails Advanced JSON Serialization

I'm looking to render an index of all articles along with a full article via json in my rails app, but I'm having a little trouble figuring out how to do it. Here is my controller now: if params[:id] @article = Article.find(params[:id]) else @article = Article.published.not_draft.by_recent.first end respond_to do |format| for...

All I need is ActiveRecord and ActiveMailer, should I use Rails/Merb?

I have a small web application that is currently running on Sinatra. It only has two pages so I don't really need controllers or many views. I have included ActiveRecord to interact with a database and ActiveMailer to send and receive mail. Would it be worth it to use Rails, or Merb on a project as small as this? I find myself adding fe...

What are some tips and tricks for developing locally without a network connection?

Everyone once in a while, I'm in a coffee shop without a network connection. I like having all the code and tools local on my laptop for these occasions. I checkout the code locally, run mysql locally, and pull down all the API documentation. What are some tools and tricks you use when you have no network? ...

Ruby Object#id warnings and Active Record

We keep seeing warnings like the following when we run our specs: Object#id will be deprecated; use Object#object_id The code in question is accessing the id of an ActiveRecord model (which is an attribute on the table, obviously, rather than the object instance ID in the Ruby VM). Does anyone know how to turn these particular war...

Rails: In ApplicationController is their a to render xml by default?

Hi, I want to be able to render both html and xml. By default html is rendered unless we add a format e.g. /myresource.xml. I want to render xml by default and only respond to .html format: GET /myresource/ returns html GET /myresource.xml returns xml I would like: GET /myresource/ returns xml GET /myresource.html returns html Is ...

How do I control user assets, but let admins see everything?

I have a Rails app where Users have Memberships to Projects (and other things, polymorphically). Users also have Roles. I want User#projects to work like a normal ActiveRecord find, but I also want administrators to have access to every project. For a while I've been doing this: class User < ActiveRecord::Base has_many :memberships,...

YUI Editor: <p> instead <br> on linebreak?

Hi How do I tell the YUI-Editor to enclose all text into <p></p> and use <p></p> instead of <br> if the user issues a linebreak? Here comes an example to illustrate what I'm trying to do: Instead of this: The quick brown fox<br>jumps over the lazy dog I would like to have this: <p><p>The quick brown fox</p><p>jumps over the lazy d...

Nokogiri (RubyGem): Find and replace HTML tags

I have the following HTML: <html> <body> <h1>Foo</h1> <p>The quick brown fox.</p> <h1>Bar</h1> <p>Jumps over the lazy dog.</p> </body> </html> ...and by using the RubyGem Nokogiri (a hpricot replacement), I'd like to change it into the following HTML: <html> <body> <p class="title">Foo</p> <p>The quick brown fox.</p> <p class="title"...

Cannot update models whith page caching

I have a very fundamental understanding problem with Rails page caching mechanism. On a rails 2.0.5 application, I use a lot of full page caching, everything's working fine, pages are served at great speed by apache. So far all the content was handled in an admin section, the cache sweepers are working well. But I have now opened the ...

YUI Editor: How to use CSS to format content of editor window?

I've implemented the YUI Editor and would like to apply a CSS to change the look of the text the user is working on inside the rich text editor. I'm working with the yui_editor plugin for ruby on rails, but that doesn't mean that a generic answer wouldn't be welcome. It's even OK if you could just point me to the correct API section and...

How do I code a rake task that runs the Rails db:migrate task?

I would like to run db:migrate VERSION=0 and then db:migrate inside of my own rake task. I am confused about how to do this. Do I need a special require statement? My rake task will reside in the lib/tasks directory of a Rails app. Thanks. ...

Why does initation of [rake db:migrate] run syntax check on rake tasks in the lib/tasks directory?

I have a rake task file for a RubyOnRails app which resides in the lib/tasks directory. Running [rake db:migrate VERSION=0] seems to force the compiler to check syntax in the lib/tasks files. If there is a file with bad syntax then [rake db:migrate] does not run. Why? So what if I have a bad file in lib/tasks. What is happening her...