ruby-on-rails

Saving data in rails session to use in form on next request

Let's say I have a table called positions (as in job positions). On the position show page I display all the detail about the job - awesome. At the bottom I need the prospective applicant to input their professional license # before continuing onto the next page which is the actual applicant creation form. I also need to take that licens...

Rails: How to add dynamic days or minutes?

Hi community In my controller i have look the commented line, i need dynamic minutes to @presentation.date def create @presentation = Presentation.new(params[:presentation]) @presentation.user_id = current_user.id @category = Category.find_by_id(params[:presentation][:category_id]) @addtime = params[:presentation][:dat...

Rails form with three models and namespace

Banging my head against this one for a long time. On Rails 2.3.2, Ruby 1.9.1. Trying to use one form to create three objects that have these relations: class Person has_one :goat end class Goat belongs_to :person has_many :kids end class Goat::Kid belongs_to :goat end Here's a summary of the schema: Person first_name l...

ruby-on-rails: mocking a route in functional test

I have a route in my routes.rb file: map.connect 'login', :controller => 'users', :action => 'login' and I have a partial being rendered in a view as: login_path This view gets called in the functional test of the controller. However, in the functional test I get the error: ActionView::TemplateError: undefined local variable o...

How to deal with time zones in a Rails app with events...

I have a Rails app for bands. Bands can import their shows which all occur in different time zones. It seems like a ton of work to store these events in UTC. I would have to figure out the time zone for any show created and then convert back to the show's local time zone when displaying to the user. Is there a simple plugin to get a ...

Passing parameters in rails redirect_to

How do we pass parameters in redirect_to in rails? I know we can pass id using this: redirect_to :action => action_name,:id => 3 If I want to pass additional parameters like some form data how to achieve it? ...

rails error "you may have ambiguous routes"

I'm having an issue with my routes and the name of the path it generates. Or I'm naming it wrong in the view or something... not totally sure. My relationships in my models are as follows: class Client < ActiveRecord::Base has_many :users has_many :elements, :through => :users end class Element < ActiveRecord::Base belongs_to :u...

(undefined method `+@' for []:Array)

Hey Everyone, I'm getting a very strange error message when I try to iterate through an array of objects. The error is NoMethodError (undefined method `+@' for []:Array): Here is the code of that loop. #go through items and see if there are any corresponding offers #All matches are stored in a hash items.each do |itemsi| bestoff...

Call a controller method from a model class

Hey everyone, I have a simple question. Is it possible to call a controller method from a model? I can't seem to figure it out if it is possible. Should I just be returning something from the model to the controller rather than trying to call a method directly? Thanks, Pat ...

How to populate a field based on selection in previous field?

In the form that we designed, we have a "States" field that allows its users to select multiple states at a time. There is a "City" field which should be populated as per the selection in the "State" field. The values in the "City" field are correctly populated if only one state is selected. However, it is not showing correctly when mult...

Naming conventions for Rails migrations

Is there a best practice naming convention for Rails migrations, particularly when editing a model? e.g. if I'm adding a column bar to the Foo model, should I name it edit_foo or add_bar_to_foo I'm assuming if I'm editing mutliple models then I should create multiple migrations, but what if I'm making multiple modifications to a single...

Rails saving IP address with every create/update request

Hello, I'd like to do the following: define a before_filter in application.rb that extracts the user's IP address and stores it anywhere, preferably in the session. define two before filters in all my models as before_create and before_update that add the current user's IP to the object to be stored. Problem: I cannot access sess...

authlogic openid auto_register feature tries to duplicate registration

I am trying to enable openid authentication on my website as well as use auto_register feature of latest authlogic_openid add-on. Everything works fine until second login. The first time user is created and logged in, but after I logout and try logging in into the system with same OpenID identifier I get user registration form with erro...

I have two versions of Ruby (1.8.7 and 1.9) installed how to specify which one for rails? or does it matter

Hello, I have Ruby 1.8.7 and 1.9 install. I run the different ones by specifying ruby or ruby1.9 when running commands. for example ruby --version or ruby1.9 --version however when I want to create new rails application the command available is rails such as: rails my_app_name How do I specify when I call the 'rails' command t...

Linking to Dynamic Content in Rails?

I have three models. User, Product, and Season. I used a standard "has many through" approach: user has_many :seasons user has_many :products, :through => :seasons product has_many :seasons product has_many :users, :through => :seasons seasons belong_to :product seasons belong_to :user On my "show" view for my users, I display the ...

Deriving a resource from the controller name - plugins?

Just wondering if there is a plugin out there that abstracts the process of deriving the instance of a current resource (or its class) from the current controller name? Currently I just classify.constantize the controller name, and if that works then I test for the id paramater and load the record if it exists. Yea, maybe it's a bit we...

Retrieving and parsing a MIME email from a database

Task given: An email is stored, byte for byte, in one or more chunks (of fixed length) in a database. This mail is to be retrieved from that database and it's contents shall be displayed to the user. I have no problem wrapping the legacy database in an ActiveRecord model, concatenating the stored chunks and so on. What I don't really kn...

AuthLogic automatically loads errors into @base and populates those errors on a signin form

(rdb:1) @account_session = AccountSession.new # => <AccountSession: no credentials provided> (rdb:1) @account_session.errors # => <Authlogic::Session::Validation::Errors:0x213cc78 @errors={}, @base=#<AccountSession: no credentials provided>> How do I prevent this? Also note, that credentials can't be provided in advance because that...

virtual attribute problems with undefined methods

I've used Virtual attributes in the past but I can't seem to get past this, and I know the answer is probably staring me in the face. I have a model like so: model Confirmation.rb class Confirmation < ActiveRecord::Base #attr_accessible :confirmation, :confirmation_token #attr_accessible :confirmation_token def confirmation_to...

Error when trying to create database with Rails, rake db:create

Hello, I'm using Ruby1.9 and Rails 2.3.4 and I have mysql-ruby (2.8.1) gem installed. when I try rake db:create I get the following Couldn't create database for {"adapter"=>"mysql", "database"=>"war_development", "username"=>"root", "password"=>nil, "host"=>"localhost"}, charset: utf8, collation: utf8_unicode_ci (if you s...