ruby-on-rails

polymorphic nested comments

Hi all i'm getting this error when I try to post a comment on a post. The error Cannot redirect to nil! /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:1104:in `redirect_to' /Users/Mister/dev/blog/app/controllers/comments_controller.rb:9 Comments/Controller: class CommentsController < ApplicationCon...

link_to_unless_current for subURLs in Rails

Hey, I'm looking for a way to use something similar to link_to_unless_current but for sub URLs, so for instance for both these URLs: /entity_name/ /entity_name/123 it will not result as a link. How can I achieve that in Rails? UPD: Resolved it my own custom way, please Ruby savvy let me know if it's good. module ApplicationHelper ...

Rolling up search result counts to a parent category

Note: I'm having a hard time explaining this, so please ask questions and I'll try to refine the problem as much as possible. Assuming I have the following category structure: - Planets - Earth - Mars And the following items/categories (nevermind that some of them don't logically make sense): - Item #1 - Category: Planet -...

Store cookie from HTTP header

How do you store a cookie with basic info. i.e. link is http://www.domain.com/index.html?ref=123 How would I store a cookie with name of "ref" and the value of "123"? ...

How to use rails routes in external classes?

I'm using prawn to generate pdfs, set up ala http://wiki.github.com/sandal/prawn/using-prawn-in-rails I'd like to access my routes so I can generate links in my pdfs, but now I'm not in a template like I used to do with prawnto, so I don't have access to the named routes. class MyPdf < Prawn::Document def to_pdf text root_path ...

Association : client.order , ok but how do you retrieve the client from the order ?

I have read the following rails guide : http://guides.rails.info/active_record_querying.html in there exemple a client has many orders and orders belong to clients. They explain how to find a lot of stuff from client. But if i want all orders from yesterday, with the corresponding client name, how do i retrieve the client from an order...

Dynamic path in new.AjaxRequest with Rails

Hello, I was wondering if there's anyway to get a 'dynamic path' into a .js file through Ruby on Rails. For example, I have the following: new Ajax.Request('/tokens/destroy/' + GRID_ID, {asynchronous:true, evalScripts:true, onComplete:function(request){load('26', 'table1', request.responseText)}, parameters:'token=' + dsrc.id + '&authe...

Using ActiveRecord::Base.transaction in a rake task?

I am writing a rake task which, at one point, uses a custom YAML file import method to seed the database. The rake task looks like: desc "Seed the database with production/ data." task :production => :environment do import_yaml 'seed/production' end At one point in the import code, I have: ActiveRecord::Base.transaction do ...

Rails caches_page, XML, and RESTful APIs

My app exposes a RESTful API using map.resources (eg: map.resources :comments). My comments controller caches_page :index, :show. In this way, I expose an XML API, so that a Flex app can post new comments. (eg POST to /comments.xml). This all worked fine until I enabled caching using the default filesystem store. Now, as far as I can ...

Using twitter gem to signup and authenticate users

Hi, I'd like to allow users the option to register using their Twitter account. Basically, I'll present them with a standard signup form (name, login, email, pwd, pwd_confirm) as well as a "Signup with Twitter" link. If a user chooses to signup with Twitter creds, then I'll create a user record in db. Then I'd like to be able to al...

Finding a specified taggable_type with acts-as-taggable-on

So in another controller, I use a find like this: @entries = Entry.find(:all, :conditions => ['live = ?', false]) to find all the entries with a false 'live' column. In my project I'm using two different taggable types, one for entries (Entry), and one for messages (Message). After looking at my tried and true code above you would th...

Rails Rspec testing not saving a transactional model

I'm currently testing my Rails controllers using RSpec. In one controller, I have a model that uses transactions, so that it will not be saved unless another nested model (whose data is filled in using fields_for) is also saved correctly. The tests hit a snag when they reach the transaction. Some debugging output proves that the model...

Determining Odd Bottleneck with Rails/Unicorn/CentOS

I have this odd bottleneck that I can't seem to put my finger on. My rails app randomly stalls which causes unicorn workers to restart. I can't seem to recreate it locally. My log shows odd things like this: Completed in 8892ms (View: 14, DB: 12) Ideas? ...

Directory listing instead of Rails site after Passenger/REE upgrade

Having updated Passenger and Ruby Enterprise Edition to the latest versions today, I am now seeing a directory listing instead of my Rails app. Here's the Passenger part of my Apache config: #LoadModule passenger_module /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so #PassengerRoot...

Rails: is it a good idea to store the view in a global var?

I'm thinking of storing the view, what i mean by view is like this: app/views/profiles/index.html.haml into this i would do $view = self then in other parts of my app i would use and edit the $view var. it might get troubles? ...

Bidirectional self referential associations

Taking Ryan Bates' asciicast as an example: http://asciicasts.com/episodes/163-self-referential-association He ends with two associations of User :friends :inverse_friends Given that a user would not care who instigated the friendship, you would want a User association that was simply :friends that consisted of both relationship...

How do I pass objects through a _url based on a routing in rails?

I want to pass the attributes associated with two objects into a path created from a route. In this case, the _url is skip_contact_letter_url. contact_letter and letter are passed through a render partial. The clip below resides in the partial. <%= link_to_remote "Skip Letter Remote #{contact_letter}", :url => skip_contact_le...

Incorrect error

If you assign an invalid date (like December 39th) to a datetime column ActiveRecord returns a "can't be blank" error when is should probably return an error like "Not a valid date" My question. Is this expected rails behavior, a bug or, something that I could patch? class ExerciseLog < ActiveRecord::Base validates_presence_of :sche...

User model declarative authorization 'if_attribute' issue

I am using authlogic (2.1.3) and declarative_authorization (0.4.1) to control access to my application. All of the authorization works as expected except user's that are assigned the Editor role can't change their (the current_user supplied by authlogic) profile settings (a part of the User model). The 'Guest' role works as expects, as...

alias_attribute and creating and method with the original attribute name causes a loop

Im trying to dynamically create a method chain in one attribute in my model. By now I have this function: def create_filtered_attribute(attribute_name) alias_attribute "#{attribute_name}_without_filter", attribute_name define_method "#{attribute_name}" do filter_words(self.send("#{attribute_name}_without...