ruby-on-rails

Associating Two Models in Rails (user and profile)

I'm new to Rails. I'm building an app that has a user model and a profile model. I want to associate these models such that: - After the user creates an account, he is automatically sent to the "create profile" page, and the profile he creates is connected to only that particular user. - Only the user who owns the profile can edit ...

Multiple database connection in Rails

I'm using active_delegate for multiple connection in Rails. Here I'm using mysql as master_database for some models,and postgresql for some other models. Problem is that when I try to access the mysql models, I'm getting the error below! Stack trace shows that, it is still using the postgresql adapter to access my mysql models! Runtime...

Need data from a many:many join in a Rails view

Its maybe not the best solution in most cases, but i want a table with data form 3 tables. class Media < ActiveRecord::Base belongs_to :user belongs_to :type has_many :ratings end class User < ActiveRecord::Base has_many :medias has_many :ratings end class Rating < ActiveRecord::Bas...

Remove assosiation instead of destroying object when :allow_destroy => true

When using the new accepts_nested_attributes_for in ActiveRecord, it's possible to use the option :allow_destroy => true. When this option is set, any hash containing nested attributes like {"_delete"=>"1", "id"=>"..."} passed to update_attributes will delete the nested object. Simple setup: class Forum < ActiveRecord::Base has_many ...

Run all Namespace Tasks with Capistrano

I have a namespace with different tasks: namespace :mytest do task :setup do; ... end; task :task1 do; ... end; task :task2 do; ... end; end When I run cap mytest I get the task `backup' does not exist. How do I create a command which calls all tasks? ...

How to get active record sessions work in Ruby on Rails application?

I'm running into a CookieOverflow error, so I want to switch to database sessions. In config/environment.rb: Uncommented: config.action_controller.session_store = :active_record_store Changed: :secret for config.action_controller.session In application.rb: Uncommented: protect_from_forgery :secret => 'ac44a970c0047c1b049c1967986af6...

Thickbox (jQuery) breaking prototype in rails.

Hey Guys, I'm creating my first rails app, and using the standard prototype library for some effects. I recently brought in Thickbox which is breaking all of the previous effects. I know there is a no conflict method for jQuery but I'm not exactly sure how to implement it? Should I just do a find/replace for $ in the jquery and thickb...

Rails: Routing subdomain to a resource

Is it possible to map a subdomain to a resource? I have a company model. Currently, using subdomain_fu, my routing file contains: map.company_root '', :controller => 'companies', :action => 'show', :conditions => { :subdomain => /.+/ } My Company model contains a "subdomain" column. Whilst this works as inten...

Plugin to use Ruby on Rails Simple I18n backend with translations overridable in the database?

Hello, Hoping some learned Rails developers here can recommend an existing Ruby on Rails plugin or gem that allows you to continue using the Simple I18n backend whilst allowing you to optionally specify translations in the database. Here's why: I have one Rails app used for many websites. For the example I'll just use 2 websites: We...

Execute commands from external file in Rails

Is there an easy way to have a rails action load up an external file of commands and then execute them? For example, I'm trying to write a bunch of rails create methods to pre-populate a bunch of tables in a database. Ideally, I'd like the action to check for the existence of the file, if it exists, run all of the commands, and then de...

Ruby on Rails session storage - how to *not* store certain fields in session store?

WARNING: Complete newbie to RoR and Ruby alert! * I have a login method that looks like this: @user = Person.find(:first, :conditions => ["email=?", params[:email]]) if @user and @user.password==params[:user_password] session[:user] = @user else flash[:warn] = 'Invalid password!' However, the user record can get very large, ...

Google Analytics and Hubspot Delay Javascript Execution

We are trying to use google analytics and hubspot on our site but they bith seem to delay the execution of the scripts on our site. We are using jQuery and the "ready" function to delay our scripts until the page is ready. Are there any ways we can delay the analytics scripts and have our scripts execute first? Thanks. ...

accessing hash inside of an array with ruby on rails

I am getting the average of all of the calls that belong to a user. A user can have many phones. So I search all the phones that belong to that user and average that phones calls and add it to an array. Now I need to average all of the calls together. This is what comes back: [{["2009-08-14", #<BigDecimal:87e1488,'0.81E2',4(8)>]=>nil, [...

Marshalling vs ActiveRecord Serialization in Ruby On Rails

What is the difference between Marshalling and ActiveRecord Serialization? Is there any particular occasion when it is preferable to use one over the other to save an object to the database? ...

Error: Attempt to call private method

Coming from a long history of C-style syntax and now trying to learn Ruby (on Rails), I've been having my share of issues with its idioms and such, but today I hit one I didn't expect to have a problem with and I can't see whatever it is that must be right in front of my face. I have a Binary class that includes a private method to deri...

JID naming strategy for a bot army?

I'm planning an XMPP bot system in which a bot is "attached" to a Rails app in background to receive commands and so on. Is is appropriate to use the same account for all apps (40+) and just changed the resource part, like this: account@host/bot1 account@host/bot2 account@host/bot2 or use totally different JIDs, like: account1@host ...

is there a simple alternative to TinyMCE?

I'm looking for a more simple text editor than TinyMCE for use with Rails, I find MCE editor, bloated, cumbersome, and problematic with many things. ...

Cucumber: rails dynamic find not working in paths.rb

I am working on rails with rspec, rspec-rails, cucumber and webrat. I am trying to learn BDD and testing in general. I have a cucumber scenario like this: Scenario: Questions List Given quiz titled "Pearl Jam" has questions named "Corduroy, Dissident" When I go to the experiment page for quiz titled "Pearl Jam" Then I shou...

Best way to generate slugs (human-readable IDs) in Rails

You know, like myblog.com/posts/donald-e-knuth. Should I do this with the built in parameterize method? What about a plugin? I could imagine a plugin being nice for handling duplicate slugs, etc. Here are some popular Github plugins -- does anyone have any experience with them? http://github.com/rsl/stringex/tree/master http://github...

Make cucumber run migrations instead of schema load

So I have some data loading in migrations, for instance a default user is created when the users table is made, and certain user Roles are created (like foo_admin) are created when the foos table is made. The problem is cucumber doesn't like this, since it does a schema load. Can I either make cucumber just run the migrations instead, ...