ruby-on-rails

Rails model fails

I have a data model which has the name 'rack'. When I generate a model with this name in my Rails project, I get errors when launching the server. load_missing_constant: uninitialized constant ActiveRecord (NameError) I am not using Rack Middleware and I don't see 'rack' as a reserved word in Ruby or Rails. Is there something I'm mi...

Weird response for controller.request.format.html? in Rails

In my main controller, I have this: class MainController < ApplicationController before_filter do |controller| logger.info "controller.request.format.html? = #{controller.request.format.html?}" logger.info "controller.request.format.fbml? = #{controller.request.format.fbml?}" controller.send :login_required if controlle...

Is there a way to ensure one object reference per record in an ActiveRecord hierarchy?

It seems when I grab some hierarchical ActiveRecord structure that there are quite a few hits to the database. I improved this using the :include option to flesh out as much of the structure as possible. Even so, it seems that ActiveRecord does not map the reciprocal sides of a relationship (e.g. parent-child) with unique references to...

has_many while respecting build strategy in factory_girl

Situation # Models class User < ActiveRecord::Base has_many :items end class Items < ActiveRecord::Base belongs_to :user validates_presence_of :user_id end # Factories Factory.define(:user) do |u| u.name "foo" end Factory.define(:user_with_items, :parent => :user) do |u| u.items {|items| [items.association(:item), ...

other alternative texthelpers in rails

I have text input I get from a variety of sources which is not HTML but is simple text. I've tried using Redcloth to fit this with HTML tags to that it integrates nicely into my site, but it doesn't get bullet points or paragraphs... I checked around an found some text helpers built in, but those also didn't do the job. http://api.ru...

How to run single test from rails test suite?

rake test ANYTHING seems to not help P.S. The question is about rails itself, not rails app. ...

How can I access a collection of acts_as_state_machine states for a particular rails model?

Is it possible to access the collection of states for the given model: class Conversation include AASM aasm_initial_state :unread aasm_state :unread aasm_state :read aasm_state :closed aasm_event :view do transitions :to => :read, :from => [:unread] end aasm_event :close do transitions :to => :closed, :from => [:read, :unrea...

bulk update objects using form in rails

I have a person model and a quotes model. Each person can have many quotes associated with them, which in turn has things like Author, Text, Url associated with them. In practice really only one person has a quotes object but all people could potentially have one. I'm trying to have a dirt simple bulk moderate tool on quotes. As in, use...

Maintaining nested model integrety with subdomains?

I have an app that uses subdomains for each 'account'. From what I have read it is good practice to "Tie all top-level requests off the current account (subdomain)". e.g. def find_users @users = @current_account.users end Simple enough. But when I start having deeply nested routes, I can't use shallow routing without losing the s...

You have a nil object when you didn't expect it!

Hey all, Following this tutorial "http://allaboutruby.wordpress.com/2009/08/08/5-minute-project-in-rails/" and i cannot get past the error in the subject. It happens when i modify "app/views/posts/show.html.erb" according to the tuorial. Now i have got it working another way previously (another tutorial) but had to put something like ...

Preserving content-type when posting a file from iPhone to Rails

I am posting a .zip file from the iPhone to a Rails server using an NSURLRequest. The problem is that the content-type of the zip file is lost in-transit. When I upload the same zip file from a web-browser to Rails, the content-type is preserved. This leads me to believe it's related to the way I'm sending it from the iPhone. Does anyone...

Ruby on Rails - Truncate parameter

In "create method" i am using parameter name i.e :name => params[:name] I have used truncate in html by adding :maxlength and :size to restrict length of name but truncating in html can be skipped easily, so i want to know the code for "truncating the parameter :name => params[:name] in controller" please suggest some code ...

How to internationalize content on ruby on rails?

How can I internationalize say a categories table (with a name column) into different languages. How about a products table (consisting of a name and description columns). Which is the best way to internationalize the content of these database tables using Ruby on Rails? ...

How should I spec this

The following spec works but I know it shouldn't be like this. I am having a hard time getting my head around rspec, in particular mocks and stubs. This is the model code class RecipeFermentable < ActiveRecord::Base belongs_to :recipe belongs_to :product def set_attributes() attrs = product.product_attributes self.ppg ...

rails - how to refer to model through string?

for example str_modelname="User" and i'd like to do str_modelname.find(:first) to find first User, but it doesn't work this way of course ...

In Spree (Rails E-commerce App) what is the preferred way to limit locales?

I only want to support German and English for a starter. As I see it I can easily limit this in the spree core locales.rb, or in the localization extension by simply deleting the locale files. But this doesn't quite seem right. I would like to configure it form my site extension, without basically forking spree. Can someone tell me how ...

Find most occurring records. RoR

suppose there are 3 fields in a mysql table. id, word and date. the word field is not a unique field, so many records have the same word. so how do i find out which word is repeated in records the most? exactly. the most repeated 5 words.. thanks ...

MySQL connections timing out/being abandoned under JRuby on Rails app on Jetty

Hi all, We're running a JRuby on Rails application on Jetty, and having reached the staging server prior to launch have suddenly hit a problem with our JDBC connections being abandoned. Here's a lovely stacktrace to illustrate: Last packet sent to the server was 12 ms ago. STACKTRACE: com.mysql.jdbc.CommunicationsException: Communica...

Error wrong number of arguments (0 for 1)

I have the form in index.erb.html file. (upload controller). When i call localhost:3000/upload/ an error appeares wrong number of arguments (0 for 1) error <% form_for :picture, :html => { :multipart => true } do |form| %> <p> <label for="picture_first_name">First name::</label> <%= form.text_field :first_name, :size => 20 ...

Can a custom path be appended to the 'new' path for Rails routes?

What I'm trying to do: I'm building a system where there are different types of post. Setting aside the models, this question is about the routes and the controller Basically /posts/new should go to an index page of sorts, while /posts/new/anything should look up the type anything and then build a form for creating a new one. How I'm...