ruby-on-rails

How to Change the environment of a rails application ?

Once I start coding a rails app, I am by default in development mode. What should I do to change my rails environment to test or production mode ? can I work in multiple environments simultaneously ? ...

How to use german umlaute in rails3 routes

Hi folks, really big problem example request http://localhost:3000/freund/in/münchen my first route in routes.rb match ':category/in/:city' => 'home#index', :constraints => {:city => /(berlin|hamburg|münchen)/ } and I get the error Routing Error No route matches "/freund/in/m%C3%BCnchen" what can I do? I postet everywhere :( ...

Problem in SQLite3 installation...

The following error comes up: C:\gem>gem install sqlite3-ruby --local Building native extensions. This could take a while... ERROR: Error installing sqlite3-ruby: ERROR: Failed to build gem native extension. C:/Ruby/bin/ruby.exe extconf.rb checking for #include <sqlite3.h> ... no sqlite3.h is missing. Install SQLite3 from htt...

How do I allow safely and inexpensively allow images on my site?

I have developed a social networking site for gardeners website, and am interested in giving users the ability to add images to their "tweets". If I allow them to upload images to the actual site, it seems like this will quickly become expensive (this is a side project, not funded by anyone than myself and my own obsessions). Let's say...

getting a 500 server error when bring up a page in rails

So I am getting a 500 server error when attempting to bring up a rhtml page in rails. When I start the WEBrick server, I get the welcome to rails homepage. The name of the app is hello. I generated the controller from the command line and it looks like class HelloController < ApplicationController def there end end I have my view (t...

Rails: editable/non-editable field depending on user permissions

I'd like to display a single form in which each user can edit different fields. Currently, the code looks like this: <% if can? :update, item %> ` <%= f.text_field :title %> <% else %> <%=h f.object.title %> <% end %> I can package this in a series of helpers (one for each field type) but I also have to check in the controller wh...

Django equivalent to "rake rails:freeze:gems" and "rake gems:unpack"

Is there and equivalent in Django to Rails' freezing and unpacking mechanism to a vendor directory so that an application becomes self-contained? ...

Preventing users from making themselves admins

In my app, I have a "User" model, which includes a number of attributes including "has_admin_rights". If true, the user is an admin, if false, they aren't. Each user has a profile, with their login name, email address, profile pic, etc. If I'm logged in as a regular user, I can click on a page called "profile", and I can edit my own ac...

Virtual attributes in rails model

In my controller I'm calling @hour.shopper.add_product within a for loop. My model looks like: class Shopper < ActiveRecord::Base attr_accessor :quantity def add_product if self.quantity.nil? || \ self.quantity == 0 self.quantity = 1 else self.quantity += 1 end self.save end end When ...

Apache server restart with Ruby on Rails

Hi - I have just restarted my apache server which is running ruby on rails. Now it isn't serving any web pages because I think that some of the Rails related services are not working. Does anyone know how to sort this out? Any help greatly appreciated. More info: error says "Ruby on Rails application could not be started" with Phusion ...

Problem with rails scaffolding (windows + netbeans + sqlite3)

I'm experimenting with Ruby on Rails. I'm using NetBeans on Windows 7. I am trying to follow this tutorial, but instead of using MySQL, I'd like to use SQLite3. Here is my database.yml file: # SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 database: db/development.sqlit...

Create instance of Rails model with has_many association prepopulated

This is best explained by example. The following is simple to do: class Foo < ActiveRecord::Base has_many :bars end 1a>> foo = Foo.new => #<Foo id: nil> 2a>> foo.bars << Bar.new => [#<Bar id: nil, foo_id: nil>] 3a>> foo.bars => [#<Bar id: nil, foo_id: nil>] However, I want all Foo objects initialized with a Bar without having to ex...

ActiveRecord object serialization and deserialization to the database

Hello, I would like to deserialize an serialized object. So it's possible to process such as (with JSON): >> l = Yea.create(:title => "foo bar") => #<Yea id: 3, title: "foo bar", created_at: "2010-07-05 21:44:54", updated_at: "2010-07-05 21:44:54"> >> j = l.to_json => "{\"yea\":{\"created_at\":\"2010-07-05T21:44:54Z\",\"title\":\"foo ...

Hello, I have a question about an error on shoulda macros

Hello I have a question about this error. I dont know why it happened to me, but in another pc it worked well. I've try this method class BookTest < ActiveSupport::TestCase should_validate_presence_of(:author_id) should_have_many(:customer_reviews) should_belong_to(:author) end And I got an error lik this 1) Error: test: Book...

Rails model validation - validates_inclusion_of...

I have a string column in a table that can have a range of predefined values. It can also include a nil value. For ex: Dog, Cat, Bird, nil. I want to write a validates_inclusion_of that checks to make sure all the values being entered fall within that predefined range. If, for ex, "Nasal Spray" is entered, it will throw an error. Wha...

How to find out when user-created calendar events are about to start [Rails]

Hey there, I'm building an online calendar in Ruby on Rails that needs to send out email notifications whenever a user-created event is about to start/finish (i.e you get a reminder when a meeting is 5 minutes away). What's the best way of figuring out when an event is about to start? Would there be a cron task that checks through all ev...

Rails Issue with associations using primary_key+foreign_key options

I want to access a legacy database schema from Rails. I have one table NAGIOS_OBJECTS with a primary key OBJECT_ID and one table NAGIOS_HOST_CHECKS that refers to NAGIOS_OBJECTS with a column HOST_OBJECT_ID. I thus defined the relations as follows: class NagiosObject < ActiveRecord::Base has_one :nagios_host_check, :foreign_key => :ho...

What is the replacement for ActionController::Base.relative_url_root?

I am porting a 2.x rails app to rails3; we'll call it foo-app. Foo-app is one section of a larger rails app and lives at main_rails_app.com/foo-app. Previously we just set up the following in our foo-app production config to ensure that our foo-app routes worked properly: ActionController::Base.relative_url_root = "/foo-app" However, ...

Rails: UI to add children from large record set to parent model in HABTM relationship

Given the parent / child HABTM relationship: class List < ActiveRecord::Base has_and_belongs_to_many :items end class Item < ActiveRecord::Base has_and_belongs_to_many :lists end I need to set up a UI to add Items (children) to a List (parent) from the List create / edit form. The wrinkle is that there are far too many Items reco...

changing ruby modules without restarting rails application

In my rails application, i have modules which are required and included in the controllers. The problem is: i have to restart the application every time i make any changes in these modules. Any solutions? Example included module #rails_application/lib/services/test.rb module Services module TestService def start 'Servic...