ruby-on-rails

Problems with ActionMailer: 501 <>: missing or malformed local part

I'm having trouble sending mail using SMTP from a Rails app. I have a Mailer class: class Mailer < ActionMailer::Base def newsletter_confirmation(subscription) recipients "[email protected]" # this is set to my email # just for testing purposes and will ...

Ruby on Rails - Can I modify data before it is saved?

Quick example: A user enters a username into a form, and I need to make that text username before storing it in the app's database, thereby making it permanently lowercase. Where would I put this code, and how would I access the data to be lowercased? Thanks. ...

Is there a way of doing filtering joined associations using named scope?

I have the following associated models class Enrollment < ActiveRecord::Base has_many :addresses end class Address < ActiveRecord::Base belongs_to :address_type end Currently I'm using the following (which I think is ugly) to filter out enrollment addresses of a certain address type. class Enrollment < ActiveRecord::Base def l...

Making a has_many/belongs_to association immutable

Let's say I have an invoice class that has many items related to it. How can I make sure that after the invoice is saved no items can be added or deleted from the invoice? I already use the immutable attributes plugin to handle regular fields but it doesn't handle associations. Using attr_readonly doesn't work either. ...

Validation of associated object results in 2 validation error messages

Hi there, I have an object Tasks with a model like this has_many :notes, :validate => true And Notes with a model like this: belongs_to :task validates_presence_of :body, :message => "cannot be empty, bonehead!" I have a /tasks/new view to create a new task (form _for), and a note for it (fields _for). I want the validation...

New to Rails, is this kind of performance normal?

I have an app and in it's only controller, an action is thus configured: def do_call response = <<EOF <real-time-stat> <awt type="integer">1</awt> <cc type="integer">5</cc> <cp type="integer">0</cp> <dc type="integer">0</dc> <ef type="float">100.0</ef> <rc type="integer">6</rc> <sl type="float">100.0</sl> <state type="integer">0</st...

Best logic for storing categories of images.

I am creating a system where a user can select any combination of four options. Then results are displayed based on their exact combination. For example, if a user chose color, text, and logo. Only results featuring color, text, and logo would return. On the other side, I am creating "templates" that will eventually be the results ret...

Is there a way in Ruby/Rails to execute code that is in a string?

So I have a database of different code samples (read snippets). The code samples are created by users. Is there a way in Rails to execute it? So for example I have the following code in my database (with id=123): return @var.reverse Is there a way for me to execute it? Something like: @var = 'Hello' @result = exec(CodeSample.find(...

Joins across multiple tables with ActiveRecord with named scopes

I love making named scopes for rails. however, I ran into somewhat of a pickle. Ive gotten pretty comfortable using named scopes for joins like so: named_scope :foo, :joins => :bar, :conditions => "bar_attribute = 'something'" Now pretend I have a table called baz which is contains a foreign key from the bar table. I need something l...

Accessing item attributes in a Rails form

If I am inside a form block in Rails, e.g form_for @widget do |f| end and am thus able to do things such as f.text_field :attribute etc, how can I also find out what the value of different attributes are in order to carry out some display logic? For instance, something like form_for @widget do |f| f.text_field :some_property f....

To implement Reddit's login feature in Rails, would I need to use RJS and remote_form_for?

A feature in Reddit that I like is the ajax login - you enter your username and password on the front page and you never leave the front page even if there is a login error. If your login succeeds, I think it simply does something like a flash[:message] onto the front page to say "login successful". If I wanted to do this in Rails, would...

Clearing the test database between unit and functional tests in Rails (factory_girl)

Recently I switched from fixtures to factory_girl to test my Ruby on Rails application. If I run rake test:units, to run the tests in my /units directory, they all run perfectly. The same is true if I run my functional tests (in my /functional directory) with rake test:functionals. However, if I simply run rake test, to run both my unit...

text search to distinguish rails projects from other types of ruby web applications - merb/sinatra/ramaze

If I want to perform a search on a directory that contains thousands of different ruby web applications and I want to find only those directories that contain rails projects, what text would I need to look for within each directory to uniquely distinguish the rails projects from the other project types? At the moment, I have decided to ...

HTML select tag allowing you to access Rails variable

<p class="acp3"> <label>Status</label> <select> <% if <option>Active</option> %> <%= account["status"] == "Active" %> <% elsif <option>Disabled</option> %> <%= account["status"] == "Disabled" %> <% end %> </select> </p> I am creating a selector with the html and I want to be able to have it access that variable...

Paperclip - View Issues

I am using Paperclip to upload numerous files to S3 (on production) and locally (in development) We started with images in which everything is working correctly. I recently developed a section to upload PDFs. The upload works beautifully but the view does not and this is where I need your help. This line of code: <% if product.marketi...

active record: create record from parent object...

this is what I mean: job has many docs. I want to create a doc, I can do: @doc = Doc.new(params[:doc]) but I'd like to enforce the parent-child relationship, since I already know the job.. something like this: @job.docs.new(params[:doc]) so that the job_id field gets ignored and only the @job object matters... does it make any se...

Should I use ON DELETE CASCADE, :dependent => :destroy, or both?

In a Rails app, I have foreign key constraints in MySQL which I set them all up manually, separate from my migrations. I'm trying to figure out whether I should use ActiveRecord's :dependent => :destroy option. For example, in my schema I have tables... users ----- log_entries ----------- user_id # Has FK constraint to users.id with ...

View helper in Paperclip interpolation

I have a paperclip interpolation that I want to use one of my view helpers for. I have the route set up so I can use foo_bar_photo_path so I just want to use that in the interpolation as well. Paperclip::Attachment.interpolations[:mykey] = lambda do |a,s foo_bar_photo_path(something,something) end Unfortunately, it whines with u...

Warbler: Where are my images

I'm using Jruby and Warbler to deploy a Jruby on Rails application to a Tomcat server. I can see all of my images when I deploy the server with Webrick: jruby -S server/script. However, when I create a .war file out of the rails directory using jruby -S warble and deploy to Tomcat, none of my images show up on the tomcat server. I notice...

If writing your own authentication, does authenticate() go in the application_controller?

I'd like to write my own authentication instead of using one of the plugins. Should my authenticate method go in the application_controller? My idea is to place it there and then in each of the controllers use a before_filter before_filter :authenticate So my authenticate method would just check if the user_id is present in the sess...