ruby-on-rails-3

version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1

≯℡__Kan透↙ 提交于 2019-12-30 00:22:27
问题 Hi i am using rails version 3.0.7 when i run rails generate model task name:string i m getting following warning WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1 WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the

Improve Rails loading time

强颜欢笑 提交于 2019-12-30 00:06:53
问题 This is a bit of a follow-up from a previous question on improving rails console loading time. The first great suggestion was to figure out which gems take too long. Next answer, suggested using :require => nil and loading those gems later. With some gems however, it's not entirely clear how to accomplish this without breaking things. Here's a list of our 'biggest offenders', I wonder if someone can suggest the best approach to loading them only when necessary? require gon: 2.730000 (2.870059

Convert .json to .csv in ruby

好久不见. 提交于 2019-12-29 17:44:37
问题 I want to convert .json file into .csv file using ruby. Pleases help me to do this. Also propose any tool to achieve this. 回答1: Try something like this: require 'csv' require 'json' csv_string = CSV.generate do |csv| JSON.parse(File.open("foo.json").read).each do |hash| csv << hash.values end end puts csv_string 回答2: To actually write to file... require 'csv' require 'json' CSV.open("your_csv.csv", "w") do |csv| #open new file for write JSON.parse(File.open("your_json.json").read).each do

Preferred way to private messages modeling in Rails 3

混江龙づ霸主 提交于 2019-12-29 15:00:34
问题 I plan to implement a private message system between members. I'm wondering what are the preferred approaches to this. Requirements are I should be able to retrieve them easily as something like this @user.conversations #Should return User objects that I sent or received messages from (but not me) @user.conversations.messages #Messages from all or specific user objects. @user.conversations.messages.unread #Unread messages When calling @user.conversations should retrieve only the people that

Rails Model Versioning with Approval

最后都变了- 提交于 2019-12-29 14:37:11
问题 I have a model that members will be able to update but their changes wont take effect until an admin approves their changes. Has anyone solved this same problem and what gems would you recommend for versioning? PaperTrail? Vestal versions? 回答1: Perhaps you could use vestal_versions with a slight twist. Add an after_update action in your controller which rolls back to the previous version if the user who made the change is not an admin. Then you can set the instance's status to pending, which

Setting up the logger in rails 3

左心房为你撑大大i 提交于 2019-12-29 12:27:27
问题 I'm trying to figure out how to use the logger with rails 3. I need to log to a file not have it in the console, but I just can't figure out how to set it up and then, how to write something to that log. I tried the rails docs but they didn't really make it clear. 回答1: By default, Rails should be logging to an environment-specific log file in your project's log directory. It will be called either test.log , development.log , or production.log depending on which environment you're running in.

“Uncaught TypeError: undefined is not a function” - Beginner Backbone.js Application

旧巷老猫 提交于 2019-12-29 11:46:10
问题 I'm setting up a pretty simple app with backbone, and I'm getting an error. Uncaught TypeError: undefined is not a function example_app.js:7 ExampleApp.initialize example_app.js:7 (anonymous function) This is where the error is showing up in Chrome Inspector (init file - example_app.js): var ExampleApp = { Models: {}, Collections: {}, Views: {}, Routers: {}, initialize: function() { var tasks = new ExampleApp.Collections.Tasks(data.tasks); new ExampleApp.Routers.Tasks({ tasks: tasks });

Capybara Ambiguity Resolution

北战南征 提交于 2019-12-29 11:31:51
问题 How do I resolve ambiguity in Capybara? For some reason I need links with the same values in a page but I can't create a test since I get the error Failure/Error: click_link("#tag1") Capybara::Ambiguous: Ambiguous match, found 2 elements matching link "#tag1" The reason why I can't avoid this is because of the design. I'm trying to recreate the twitter page with tweets/tags on the right and the tags on the left of the page. Therefore it will be inevitable that identical links page shows up on

Capybara Ambiguity Resolution

瘦欲@ 提交于 2019-12-29 11:31:16
问题 How do I resolve ambiguity in Capybara? For some reason I need links with the same values in a page but I can't create a test since I get the error Failure/Error: click_link("#tag1") Capybara::Ambiguous: Ambiguous match, found 2 elements matching link "#tag1" The reason why I can't avoid this is because of the design. I'm trying to recreate the twitter page with tweets/tags on the right and the tags on the left of the page. Therefore it will be inevitable that identical links page shows up on

Rails - Help understanding how to use :dependent => :destroy

点点圈 提交于 2019-12-29 09:09:10
问题 I have the following models: User (id) Project (id) Permission (project_id, user_id) Thread (project_id) ThreadParticipation (thread_id, user_id) So that's working nicely, problem is this. When a user leaves or is removed from a project, I need all their ThreadParticipation's for that project deleted. Example, so if user(15), leaves project(3) by deleting the permission (user_id =>15, project_id => 3), I need rails to automatically then delete all related ThreadParticipation records (where