ruby-on-rails-3.1

Uncaught TypeError: Cannot call method 'extend' of undefined

天涯浪子 提交于 2019-12-10 17:11:36
问题 I am trying to get a CoffeeScript class to extend a Backbone.Model. I built a brand new rails 3.1 app, created a scaffold of 'Stone', with 3 attributes, and patched a snippet of the Todos.coffee example into stones.js.coffee. I have both backbone.js and underscore.js in the app/assets/javascripts folder. When I run this under the Chrome Java console, I get the message above in the console log. Any ideas? Actual code follows: $ -> class Todo extends Backbone.Model # Default attributes for the

Functions in controller.js.coffee

久未见 提交于 2019-12-10 16:46:51
问题 I'm having some trouble creating functions with CoffeeScript, I guess I've missed something. For my users controller I'd like to create client-side validation for a signup form. I think I've missed something fundamental with how this all works. <%= form_for @user, :html => {:onsubmit => "return validate_signup_form();"} do |f| %> CoffeeScript ( assets/users.js.coffee ): validate_signup_form = () -> alert "Hi" return false Expected output: var validate_signup_form; validate_signup_form =

Testing the relationships and Methods In Model using Rspec

混江龙づ霸主 提交于 2019-12-10 15:54:34
问题 I m working on rails project and i m new on rails and I want to test my model relationships and methods in model using rspec. How could I do this my model relationships are like this class Idea < ActiveRecord::Base belongs_to :person belongs_to :company has_many :votes validates_presence_of :title, :description def published? if self.status == "published" return true else return false end end def image_present if self.image_url return self.image_url else return "/images/image_not_found.jpg"

Rails 3.1 named_scope

柔情痞子 提交于 2019-12-10 15:39:33
问题 What is the Rails 3.1 of writing the code below: named_scope :min_2_items_last_90_days, { :include => { :orders => :order_items }, :conditions => ['orders.created_at >= ?', 90.days.ago], :group => 'people.id', :having => 'COUNT(order_items.id) >= 2' } 回答1: While writing it as scope :min_2_items_last_90_days, where(...) is syntactically correct, it probably (like your original code) doesn't do quite what you think. In both cases the 90.days.ago is evaluated once only, when the class is loaded,

Rails 3.1 - JS - Socket.io-emit in *.js.erb gets not executed and prevents execution of jQuery-Function

最后都变了- 提交于 2019-12-10 15:27:52
问题 I want to use node.js with my Rails-Project to serve asynchronous io. I don't want to use juggernaut, faye or something like this, because I need clean connections with web-socket, server-sent events and spdy without an alternative. My first try to use node.js is now to use Socket.io, just to get in use with serving data to a node.js-module with JavaScript. But it doesn't work at all. My application.js looks like this: // This is a manifest file that'll be compiled into including all the

Cross-thread violation on rb_gc()

ぃ、小莉子 提交于 2019-12-10 14:16:55
问题 The codebase I'm working on was recently upgraded from Ruby 1.9.2 to Ruby 1.9.3 and from Rails 3.1 to Rails 3.2.2. Since I'm using RVM I simply did rvm install 1.9.3 which I would have expected to be all that was necessary. When I run rails s I get the error [BUG] cross-thread violation on rb_gc() I've found a number of links relating to this problem. There is one on StackOverflow, but it doesn't really give an answer. The most promising answer is on the RVM site: In every case of this I have

bundle exec with heroku - is it necessary?

我们两清 提交于 2019-12-10 13:32:34
问题 I recently set up a Cedar (Rails 3.1) app on Heroku, and to run, for example, a migration, you'd do heroku run rake db:migrate I learned that it's good practice to use "bundle exec" before any rake command (as Katz says http://yehudakatz.com/). So, I thought perhaps the following is actually better practice: heroku run bundle exec rake db:migrate But to reduce verbosity, is it alright to use the former command, or is the one with bundle exec critical? 回答1: On Heroku when the slug is compiled

Copy of environments/development asset path cannot find jquery-ui-rails in gems directories

房东的猫 提交于 2019-12-10 13:13:46
问题 I copied config/environments/development.rb to config/environments/ci.rb. When I run with RAILS_ENV=development, the asset search path includes my gem vendor directories, in particular for jquery-ui-rails. However, when I run with RAILS_ENV=ci it does not. From the console, Rails.application.config.assets.paths evaluates to the following with development irb(main):002:0> Rails.application.config.assets.paths => ["/var/www/ci/conflux/app/assets/images", "/var/www/ci/conflux/app/assets

Rails 3.1.4 - Render :text

十年热恋 提交于 2019-12-10 12:59:30
问题 I'm updating my rails 2 apps to rails 3 and find that the use of 'render :text' does not behave the same anymore. @results is an array. In my controller: render :text => "<ul>#{@results}</ul>" It's returning the whole array as a string rather than iterating through each value: <ul> [" <li>Steve</li> ", " <li>John</li> "] </ul> Worked fine in Rails 2.x but not in 3. How do I fix this? I'm expecting a result of: <ul> <li>Steve</li> <li>John</li> </ul> 回答1: I know this question is for Rails 3.1

ActiveRecord::Relation issue on acts-as-taggable-on

孤者浪人 提交于 2019-12-10 12:17:14
问题 I am a rails newbie. I am trying to implement acts-as-taggable-on on my sample app. I am able to enter multiple tags using tag_list but facing issues searching them. This is what I got. I used scaffold User to generate the controller & model. class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name t.text :tags t.timestamps end end end My User Model is class User < ActiveRecord::Base serialize :tags acts_as_taggable_on :tags scope :by_join_date, order(