ruby-on-rails-3

Rails: attributes not being saved even though I called @user.save

独自空忆成欢 提交于 2019-12-24 04:16:07
问题 I'm running this function, and I KNOW that it gets called because the redirect_to is working. But for some reason, @user isn't! If it helps, @user is devise based. def make_feed_preference @user = current_user #@user.feed_preference = params[:preference] @user.feed_preference = "time" @user.name = "Shoo Nabarrr" @user.karma = 666 @user.save redirect_to '/posts' end I fixed it myself. I had to create a new class attached to users in order to get it to work. Lol. 回答1: Do you have any

Rails, route_path breaks when there is @ symbol in username

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 04:08:27
问题 I get a RoutingError whenever a username has an @ symbol in it: No route matches {:controller=>"users", :action=>"show", :username=>"abc@shin.com"} My routes looks like this: match 'users/:username' => 'users#show', :as => :show_other_user And my view: <% for user in @users %> <tr> <td><%= image_tag avatar_url(user, 50) %></td> <td><%= link_to user.name, show_other_user_path(:username => user.username) %></td> <td><%= common_friends(current_user, user).size %></td> </tr> <% end %> Everything

Error running autotest on Windows 7 with Rails 3, Ruby 1.9.2

走远了吗. 提交于 2019-12-24 04:06:15
问题 Installing and running Rails 3 and Ruby 1.9.2 on Windows 7 went rather smooth. It's only now that I want to run autotest that I'm running into problems. The error looks frustratingly simple, but I can't figure out how to solve it. I have the following gems in my Gemfile: gem 'autotest' gem 'autotest-rails-pure' But then when I run bundle exec autotest , I get: loading autotest/rails style: Rails C:\bin\Ruby192\bin\ruby -I.;lib;test -rubygems -e "['test/unit', 'test/unit/helpers/users_helper

Using Rails Inflections with `rails generate`

蓝咒 提交于 2019-12-24 03:56:30
问题 I'm trying to generate a model called ClassAttendance , but Rails keeps naming the migrations class_attendances . I've tried correcting this problem by placing the following code the following code in \config\initializers\inflections.rb : ActiveSupport::Inflector.inflections do |inflect| inflect.uncountable "attendance" end This seems to work fine in the rails console: $ rails console Loading development environment (Rails 3.2.6) irb(main):001:0> "attendance".pluralize => "attendance"

Efficient sorting of rows by multiple columns in Rails 3

这一生的挚爱 提交于 2019-12-24 03:36:33
问题 I have a table name transactions with following columns created_at | debit | credit | balance | account_id 2012-2-2 02:22:22 | 3000 | 0 | 0 | 8 2012-2-2 07:22:22 | 500 | 1000 | 0 | 8 2012-2-2 09:22:22 | 0 | 8000 | 0 | 8 2012-3-3 19:17:20 | 1000 | 0 | 0 | 8 2012-3-3 04:02:22 | 0 | 8000 | 0 | 8 Before calculating balance I need to sort transactions by date (i.e. daily) then sort by debit (higher debit must come first) I have a million transactions distinguished by account_id. What is efficient

Google custom search API with pagination

有些话、适合烂在心里 提交于 2019-12-24 03:34:39
问题 I have this method that puts the links of the 10 results from the Google custom search API into an array: require 'json' require 'open-uri' def create search = params[:search][:search] base_url = "https://www.googleapis.com/customsearch/v1?" stream = open("#{base_url}key=XXXXXXXXXXXXX&cx=XXXXXXXXXX&q=#{search}&start=#{i}&alt=json") raise 'web service error' if (stream.status.first != '200') result = JSON.parse(stream.read) @new = [] result['items'].each do |r| @new << r['link'] end end and my

Resque is returning Mysql2::Error: closed MySQL connection: SHOW FIELDS FROM `users`

只愿长相守 提交于 2019-12-24 03:34:18
问题 Resque is returning Mysql2::Error: closed MySQL connection: SHOW FIELDS FROM users Worker 8608f362-819b-4c15-b42b-69c4df00d27b:1 on low at about 16 hours ago Class AddLiveView Arguments 4383 {"remote_ip"=>"184.72.47.71", "expires"=>true} Exception ActiveRecord::StatementInvalid Error Mysql2::Error: closed MySQL connection: SHOW FIELDS FROM `users` /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `query' /app/vendor/bundle

jquery:install doesn't work in Rails

烂漫一生 提交于 2019-12-24 03:30:38
问题 I have installed gem jquery-rails in Rails 3.1 app. But line below rails generate jquery:install --ui Getting error: Could not find generator jquery:install. 回答1: In rails 3.1, because jquery is the default, you no longer need to install it, it will be required in app/assets/jquery/application.js and it will look something like: //= require jquery //= require jquery_ujs //= require_tree . You can verify which generators are available by executing rails g without anything else: rails g 回答2:

jquery:install doesn't work in Rails

心已入冬 提交于 2019-12-24 03:30:11
问题 I have installed gem jquery-rails in Rails 3.1 app. But line below rails generate jquery:install --ui Getting error: Could not find generator jquery:install. 回答1: In rails 3.1, because jquery is the default, you no longer need to install it, it will be required in app/assets/jquery/application.js and it will look something like: //= require jquery //= require jquery_ujs //= require_tree . You can verify which generators are available by executing rails g without anything else: rails g 回答2:

Rails: Resource reachable from two routes, or better approach?

淺唱寂寞╮ 提交于 2019-12-24 03:29:55
问题 I'm working on an app where users can share photos. The photos can optionally belong to a collection, but don't have to. Currently users can look through all photos via: photos/id . I think it would also make sense if they could browse through the photos for a particular collection through collections/id/photos So, this would mean that photos were both a top level resource and a nested resource. I suppose I could set this up in the routes like so: resources :photos resources :collections do