ruby-on-rails

Passing two variables to separate table...associations problem

I have developed an application and I seem to be having some problems with my associations. I have the following: class User < ActiveRecord::Base acts_as_authentic has_many :questions, :dependent => :destroy has_many :sites , :dependent => :destroy end Questions class Question < ActiveRecord::Base has_many :sites, :dependent...

Sphinx: change column set for searching in runtime

I use Ultrasphinx gem plugin as a wrapper for accessing Sphinx search daemon. My model declaration: class Foo < ActiveRecord::Base is_indexed :fields => ['content', 'private_notes', 'user_id'] Client code: filters = {} if type == "private" # search only in `content` column filters['user_id'] = current_user.id else # se...

How can I refactor out needing so many for-loops in rails?

I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many Contacts Campaign also has many Models which are templates: (Email, Call, and Letter). Because I am looking for overdue on each, I created an array called Event which I'd like to loop through that contains ['email', 'call', 'letter']. I need a list ...

Authlogic Current User Question - hiding admin links...

I think I am missing something while using the Authlogic gem w/ Rails. To set the stage I have multiple users and each user can create posts and comments. Upon the display of a post or comment I would like to give the user who created them the option to edit or destroy. I am successfully using the following code to hide and show element...

Connect Rails model to non-rails database

I'm creating a new web application (Rails 3 beta), of which pieces of it will access data from a legacy mysql database that a current php application is using. I do not wish to modify the legacy db schema, I just want to be able to read/write to it, as well as the rails application having it's own database using activerecord for the new...

What is the best way using multiple lines of <% %> Tag or <% %> Tag with multiple lines?

Sorry if the title is not enough to understand what i am asking about. I am rails developer and i used multiple lines of <% %> in my views but now i realized that it's not best practice so i came here and like to you all excellent guys what is the correct way in ROR? For example if i required to something like following <% user =User....

Administrator account: Where, when and how?

Where, when and how to create the administrator account/user for a private website? So what I am asking is what's the preferable technique for creating that first administrator account/user. In my case it's for a private webapplication. I am talking about the account/user that will own the application and will if needed create/promote ...

Testing devise with shoulda

Hello, I'm having some difficulties in testing devise with shoulda: 2) Error: test: handle :index logged as admin should redirect to Daily page. (Admin::DailyClosesControllerTest): NoMethodError: undefined method `env' for nil:NilClass devise (1.0.6) [v] lib/devise/test_helpers.rb:52:in `setup_controller_for_warden' I have this in my...

NameError in CompetitorsController#index

Hi all I am getting this problem when I run this code in server. In my localhost everything is running fine. But when I deploy my code in the server it shows me the error. I am using FERRET SERARCH IN MODEL. NameError in CompetitorsController#index uninitialized constant CompetitorsController::Competitor /opt/ruby_enterprise/lib/rub...

named_scope + average is causing the table to be specified more then once in the sql query run on postgresql

I have a named scopes like so... named_scope :gender, lambda { |gender| { :joins => {:survey_session => :profile }, :conditions => { :survey_sessions => { :profiles => { :gender => gender } } } } } and when I call it everything works fine. I also have this average method I call... Answer.average(:rating, :include => {:survey_sessi...

Can I deploy a Ruby on Rails webapp to an IIS webserver?

Can I deploy a Ruby on Rails webapp to an IIS webserver? Is there any solid support for this somehow? ...

Returning a 1x1 .gif as a response in Rails

Hi, I'm building a Rails app that does conversion tracking on outside sites. I'd like to allow users to paste an image tag in their conversion pages (like AdWords), and whenever that image is requested, a conversion registers in my app. respond_to do |format| if @conversion.save flash[:notice] = 'Conversion was successfully creat...

how to access picture stored in database via http request in rails

As per title. And is there anyway to cache such data? thanks ...

Handling Email Bouncebacks in Rails

Hi there, I've built a very basic CRM system for my rails app that allows me to send weekly user activity digests with custom text and create multi-part marketing messages which I can configure and send through a basic admin interface. I'm happy with what I've put together on the send-side of things (minus the fact that I haven't tried...

Rails attribute alias

Hi, I was just wondering if it's possible to "rename" an association in Rails. Let's assume : # An ActiveRecord Class named SomeModelASubModel (some_model_a_sub_model.rb) class SomeModelASubModel < ActiveRecord::Base has_many :some_model_a_sub_model_items end # An ActiveRecord Class named SomeModelASubModelItem (some_model_a_sub_mod...

NameError when using act_as_ferret

Hi all I am getting this error when I am using acts_as_ferret :fields =>[:competitor], :remote => true NameError in PartController#index uninitialized constant PartController::Competitor My Model class Competitor < ActiveRecord::Base validates_presence_of :fee_earner_id, :notes belongs_to :fee_earner belongs_to :country be...

Rails 3 ActiveModel Nested Class I18n

Given the following class definition in ruby: class Conversation class Message include ActiveModel::Validations attr_accessor :quantity validates :quantity, :presence => true end end How can you use i18n to customize to error message. For example the correct lookup for the class Conversation would be activemodel: er...

Ruby on Rails vs Grails vs. Spring ROO vs. Spring App

Hi, I'm planning on writing a simple web application that will be used by lots of users (as complicated as a simple bookmarking app) and I'm trying to decide which framework/language to use. I'm very experienced with Spring/Hibernate and Java in general but new to both Grails and RoR (and Spring ROO). The only reason I'm considering R...

Howto: Access a second related model in a nested attribute builder block

I have a basic has_many through relationship: class Foo < ActiveRecord::Base has_many :bars, :dependent => :destroy has_many :wtfs :through => :bars accepts_nested_attributes_for :bars, :wtfs end On my crud forms I have a builder block for the wtf, but I need the label to come from the bar (an attribute called label for instanc...

Which Ruby gem should I use for updating a Twitter or Facebook status along with authlogic_rpx?

Hi, My Rails webapp uses tardate's excellent authlogic_rpx gem so that users can register and sign in using their Twitter or Facebook account. Now I need to update a user Twitter or Facebook status. Which gem should I use for Twitter? and for Facebook? Or should I prefer Net::HTTP for both? Since the users authorised my app through au...