ruby-on-rails

Extending core Ruby classes when in Rails

Rails provides a number of extensions to core Ruby classes. One of these is the to_sentence method, added to the Array class, allowing for the following: ['a', 'b', 'c'].to_sentence # gives: "a, b, and c" I would like to extend this method to allow it to take a block, so that you can do something like the following (where people is an...

Ruby on Rails routing

I am a newcomer to RoR and have a question about routing. I have set up an application and a simple user login system (yes I know there is already a login generator out there, I just wanted to try it for myself). I have a before_filter on a certain action that checks if the user is logged in or not. If not, it redirects them to the lo...

Best practices for using memcached in Rails?

Hello everybody, as database transcations in our app are getting more and more time consuming, we have started to use memcached to reduce the amount of queries passed to MySQL. All in all, it works fine and really saves a lot of time. But as caching was "silently appearing" as a workaround to give the app more juice, a lot of our mode...

Passing data between controllers with the session RESTfully

I'm using a hideous pattern in my code and I know there must be a better way to do this. Help me rethink what I'm doing. My website is a kind of discussion forum. All replies to discussions are done on the DiscussionsController#show page, inline. Some replies are invalid, though - for example, if you try and post a reply that has no t...

Updating the db 6000 times will take few minutes ?

I am writing a test program with Ruby and ActiveRecord, and it reads a document which is like 6000 words long. And then I just tally up the words by recordWord = Word.find_by_s(word); if (recordWord.nil?) recordWord = Word.new recordWord.s = word end if recordWord.count.nil? recordWord.count = 1 else recordWord.count += 1 end r...

What do you recommend for deploying web apps?

For deploying applications (Ruby apps, in my case) I've used Capistrano and currently use Vlad the Deployer. What do you use for deployment, and why? ...

redirect_to in private methods

I have an action that is calling a private method. If an error occurs in this private method *redirect_to* is called. The issue is that it gets to *redirect_to* and according to the logs it is redirecting but doesn't on the client end and results in an error. Any suggestions? Thanks! ...

I can send an email from my Rails app, but not an SMS text through an email gateway...

I have application that needs to send emails and sms text messages. It sends emails just fine, but when I try to send text messages using email gateways (for verizon, [email protected]) I get nothing. I have texted the phone using though the email gateway using my gmail account, so I know it works. I would just think that from my ap...

Rails: How do I keep a complex app RESTful?

I always try to make my applications as RESTful as possible but I've recently begun working on a complex project that requires multiple additional methods in my controller. I normally achieve this by adding another :collection to the route but it seems like a workaround and in on scenario I have 5. Are there any best practices for han...

problem with daemons gem in rails

Hello, I'm using daemons gem with Rails in addition to daemon_generator plugin. I'm getting this output in the daemons log file: Logfile created on Sat May 09 20:10:35 -0700 2009 by / -below you find the most recent exception thrown, this will be likely (but not certainly) the exception that made the application exit abnormally *** #<...

Transferring variables between models using a view.

I am creating a very simple book review site and it needs the ability to allow the user to add little comments about a book. Now I have my two tables, one for the book and one for the comments and now need a way to transfer data between the two because i find the way rails handles things quite puzzling. So my book model contains "has_ma...

uninitialized constant error, while using JSON and Facebook connect with rails

I'm following the tutorial here http://applicake.com/posts/54-integrating-facebook-connect-with-rails-applications to set up facebook connect. It almost worked, except for the last step :-( I'm getting a JSON error, inspite of installing the JSON plugin. I did gem install json How do I fix the problem? Error in the view: uninitiali...

Rails error "NoMethodError" - My first ruby app

Hi, I am absolutely and totally new to rails, so the answer is probably very simple. Here goes: My page is generating this error NoMethodError in Tasks#new Showing app/views/tasks/new.erb where line #3 raised: undefined method `tasks_path' for # Here is the view: <% form_for(@task) do |f| %> <%= f.error_messages %> <%= f...

Nested object creation with JSON in Rails

How do I pass JSON to a RAILS application so it will created nested child objects in a has_many relationship? Here's what I have so far: Two model objects. class Commute < ActiveRecord::Base has_many :locations accepts_nested_attributes_for :locations, :allow_destroy => true end class Location < ActiveRecord::Base belongs_to :c...

Can one rely on the auto-incrementing primary key in your database?

In my present Rails application, I am resolving scheduling conflicts by sorting the models by the "created_at" field. However, I realized that when inserting multiple models from a form that allows this, all of the created_at times are exactly the same! This is more a question of best programming practices: Can your application rely on ...

How can I make this query to detect multiple accounts more efficient & play well w/ has_many?

In my User model, I want to search for whether a user has multiple accounts (aka 'multis'). Users have sessions; sessions are customized to set creator_id = ID of first user the session was logged in as, and updater_id = ID of last user the session was logged in as (Both columns are indexed.) If I detect that the two are different...

Not sure where (model or controller) to define my find method

(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a public method in my albums controller: <% albums_feature = find_albums_with_feature(feature.id) %> It generates a NoMethodError. So I copied the method into my Album model and tried calling it from the view as: <% albums_feature = Album.find_albums_w...

What URL should I give Google Maps API so it recognises the key created for a local Rails apps run with Passenger?

Hi, I've been working on a Google Maps based Rails app and it was working fine until I installed Phusion's Passenger and now Google Maps API won't recognise the API Key which I generated for http://localhost:3000. Now I'm running Passenger, the URL for my app is http://mygooglemapsapp.local. I've generated a Google Maps API key using ...

Passing a method to validates_format_of

I want to do this: validates_format_of :email, :with => email_regex def email_regex email_name_regex = '[A-Z0-9_\.%\+\-]+' domain_head_regex = '(?:[A-Z0-9\-]+\.)+' domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)' return /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i end but I am getting an error saying ...

Rails escaping quotation mark in link_to_function partial

I have a little piece of rails code which lets users enter a review. If one already is written it displays the current review with a link to edit it. <div id="text_area"> <% if @user_rating.review.blank? %> <%= render :partial => "reviews/text_area" %> <% else %> <%= simple_format @user_rating....