ruby-on-rails-3.2

Rails 4 remove test generators (especially test_unit)

∥☆過路亽.° 提交于 2019-12-04 19:58:10
问题 How I can remove test_unit generators to make them disappear from the rails generate list? I have already tried some ways that did not work for me : config.generators do |g| g.test_framework nil end create app with -T option. My rails g output: [a lot of other generators skipped] TestUnit: test_unit:controller test_unit:helper test_unit:integration test_unit:mailer test_unit:model test_unit:plugin test_unit:scaffold 回答1: In your config/application.rb where you have the generations settings,

Is it possible to order multiple columns by using the `ORDER BY FIELD` statement?

雨燕双飞 提交于 2019-12-04 19:48:08
I am using Ruby on Rails 3.2.2 and I would like to know if it is possible to order multiple columns/fields by using the ORDER BY FIELD statement (for example, as made in the Model.order("orders_count, created_at, name, ...") but for ORDER BY FIELD ). If so, how can I " ORDER BY FIELDS "? P.S. : As written in a previous answer , in order to order my records relating to one column I am using the Model.order("field(status, 'blocked', 'unpublished', 'published')") statement. 来源: https://stackoverflow.com/questions/10646877/is-it-possible-to-order-multiple-columns-by-using-the-order-by-field

Return records distinct on one column but order by another column

醉酒当歌 提交于 2019-12-04 19:44:37
I am building a Rails 3 app with a pretty standard message model. I would like to return the most recently created message records for each unique conversation_id. It seems like a fairly simple task, but I have not been able to code or find a working solution. Admittedly, I am not super SQL savvy either (as I have gotten by with mainly Active Record queries thus far). Here is what I'm trying to accomplish. Sample messages table: | id | sender_id | receiver_id | conversation_id | subject | body | created_at | | 1 | * | * | 1 | * | * | 16:01 | | 2 | * | * | 2 | * | * | 17:03 | | 3 | * | * | 1 |

Create a drop down list of many links in rails

天涯浪子 提交于 2019-12-04 19:42:47
I have many links about for example link1, link2, link3, link4 ...link9. I have to add those links in the drop down. I tried with rails select_tag and also with html tag Using html select tag <span class="device_update"> <select> <option value="link1"><%= link_to "link1", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option> <option value="link2"><%= link_to "link2", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option> <option value="link3"><%= link_to "link3", "#",{:remote => true, 'data-toggle' => "modal", 'data

A quiz game on ruby on rails [closed]

半腔热情 提交于 2019-12-04 19:03:28
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 5 years ago . I am working on a quiz game using ruby on rails. I have created the basic authentication and other pages. Now I am starting work on creating the main game. I want to get an opinion about what method should I use i.e. create a seperate view for each question or is there a gem to do the same? Or some other method I would suggest to use a nested form with a partial as described

How to access params in the callback of a Rails model?

纵饮孤独 提交于 2019-12-04 19:02:50
问题 I have a callback of a model that needs to create a dependent object based on another field entered in the form. But params is undefined in the callback method. Is there another way to access it? What's the proper way to pass a callback method parameters from a form? class User < ActiveRecord::Base attr_accessible :name has_many :enrollments after_create :create_enrollment_log private def create_enrollment_log enrollments.create!(status: 'signed up', started: params[:sign_up_date]) end end

How do I rename a file with Fog?

蹲街弑〆低调 提交于 2019-12-04 18:05:20
问题 I have a rails 3.2 app. Using fog to store files in S3. I would like to write a script to rename all of the files that have been uploaded. I can't seem to find any fog documentation in this area. Is this possible with fog? Do I need another gem? 回答1: The bad news is you need to do a get/create/destroy foo = bucket.files.get 'foo' bar = bucket.files.create :key => 'bar', :body => foo.body foo.destroy The good news is if you're doing it from ec2 in the same region it will probably happen as

Devise + Omniauth call action passthru on login Facebook

荒凉一梦 提交于 2019-12-04 16:25:00
When I try to login with Facebook using Omniauth and Devise, passthru is called instead of facebook . How do I pass in the link_to : user_omniauth_authorize_path(:facebook) I've revised the code many times and tried to use this route: devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru' end and devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } But the error is same. I have the action facebook in my users/omniauth_callbacks_controller.rb I just flailed

How to serialize - deserialize params hash object?

梦想的初衷 提交于 2019-12-04 15:42:10
how would I do such a thing? I want to be able to store the params object into a string attribute of a model, and be able to deserialize it into params hash object again, how would I do this in ruby? or is there an out of the box solution in rails? Active Record can serialize any object in text columns using YAML . To do so, you must specify this with a call to the class method serialize. This makes it possible to store arrays, hashes, and other non-mappable objects without doing any additional work. class User < ActiveRecord::Base serialize :preferences end user = User.create(preferences:

DBI Row / delegate behavior between ruby 1.8.7 and 2.1

╄→гoц情女王★ 提交于 2019-12-04 14:22:47
I execute the following code in ruby 1.8.7 to read rows from my database: require 'dbi' db_conn_handle = DBI.connect("DBI:Mysql:host=localhost;database=mydb;port=3306", "root") sth = db_conn_handle.prepare("select accounts.id, accounts.name from accounts;") sth.execute info = sth.to_a puts "Info: #{info[0].class}" info.each do |x, y| puts "#{x} ... #{y}" end From the output it is clear that info[0].class is DBI::Row. This code works perfectly when executed with ruby 1.8.7 (rails 3.2.17) When I try executing it in ruby 2.1.5 / rails 3.2.17, it gives the following error: /home/rjain/.rvm/rubies