ruby-on-rails-3.2

Rails - Show A Random Record But Not The Current

◇◆丶佛笑我妖孽 提交于 2019-12-08 02:38:06
问题 At the end of a blog post I would like to display a teaser link to another random post. Obviously this link should be NOT a teaser for the current post itself. I figured already out how to choose a random post, but there is still the chance that the teaser link is a link to the current post. I couldn't figure out, how can I exclude this case. Here is my controller: def show @post = Post.find(params[:id]) @staff_pickrandom = Post.where(staff_pick:true).order("RANDOM()").limit(1) end I am quite

When using Rails 3.2.22.2, what is the highest Ruby Version I can use?

好久不见. 提交于 2019-12-08 02:18:11
问题 I'm looking to upgrade a large application with many gems. It's currently on Ruby 1.9.3p551. I've heard that I can upgrade to Ruby 2.2 but not any higher. Is this version of Rails compatible with Ruby 2.2.5, alternatively, how can I find out the highest possible version supported. 回答1: Quote from this blog post Rails 3.2.22 includes all the commits from the 3-2-stable branch. This mean that now Rails 3.2 supports Ruby 2.2. Since Rails 3.2 doesn't receive bug fixes anymore (only severe

Huge json object to excel?

主宰稳场 提交于 2019-12-08 01:56:53
问题 I have a PHP application which has a table with more then 10000 rows and I am trying to export that into an excel sheet via my ROR application but my request is getting timed out on the server by PHP application.So I was wondering is there any elegant way to solve this problem. I come up with 2 solutions. First is doing a batch processing (need to read about as I am new with it) and the other is that my php application will send a large json object and my ruby app will read that json object

How to change the default value of check_box ? in Ruby on Rails

对着背影说爱祢 提交于 2019-12-08 01:44:33
问题 How to change the default value of check_box ? views/doctors/_form.html.erb <%= form_for(@doctor) do |f| %> <%= f.label :pass %><br> <%= f.check_box :pass, {checked: true, checked_value: "yes", unchecked_value: "No"} %> <%= f.submit %> <% end %> The data type of :pass attribute was string , But still it was not created any value for :pass attribute in DB. So, I changed the data type of :pass attribute into boolean. Now it is working with True and False But, I Just want to change the True and

Rails: Sunspot text searching with model associations, using :through

旧时模样 提交于 2019-12-08 01:33:39
问题 How do I search with associations and through with sunspot? class StaticController < ApplicationController def search @search = Sunspot.search Business, Service do fulltext params[:q] paginate :per_page => 10 order_by_geodist(:location, *Geocoder.coordinates(params[:loc])) end @biz = @search.results end class Business < ActiveRecord::Base attr_accessible :name has_many :services, :through => :professionals searchable do text :name #name in business column # how to do I get the services? end

Mongoid 3 - access map_reduce results

情到浓时终转凉″ 提交于 2019-12-07 23:43:41
问题 In mongoid 2, this used to work: mr_collection = self.collection.map_reduce(map, reduce, { :query => query, :finalize => finalize, :out => {:replace => 'mr_results'} }) limit = (options[:limit] || 10) skip = (options[:skip].to_i || nil) page = if skip >= limit ((skip+limit) / limit) else 1 end sort = if options[:sort_by_vintage] [['value.vy', :desc], ['value.s', (options[:sort] || :desc)], ['value.pml', :asc]] elsif options[:sort_by_sDate] [['value.sDate', :desc], ['value.s', (options[:sort]

migrate error: undefined method `cache' for Gem:Module

三世轮回 提交于 2019-12-07 19:34:45
问题 while migrating by rails app am getting this error undefined method `cache' for Gem:Module Am using Rails 3.2.9 Ruby 1.8.7 Ubuntu 12.04 rake db:migrate --trace /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/object.rb:138: warning: method redefined; discarding old try_dup /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/symbol.rb:3: warning: method redefined; discarding old try_dup /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib

Add datepicker with rails 3.2.11, simple_form and bootstrap

喜欢而已 提交于 2019-12-07 18:52:24
问题 I am trying to implement datepicker in my simple_form much as has been covered here: How do i write a cleaner date picker input for SimpleForm I create the custom class: # app/inputs/date_picker_input.rb class DatePickerInput < SimpleForm::Inputs::StringInput .... end I then add: `$("input.date_picker").datepicker(); at the bottom of application.js and use the code: <%= f.input :deadline, :as => :date_picker %> However, a datepicker is not activated, nor is an error thrown. Could this be an

Helper methods to be used in Controllers AND Views in Rails

流过昼夜 提交于 2019-12-07 18:08:53
问题 I understand I can put a helper method in a Helper class inside the helper folder in Rails. Then that method can be used in any view. And I understand I can put methods in the ApplicationController class and that method can be used in any controller. Where's the proper place to put a method that is frequently used in both controllers and views? 回答1: You can put it in the controller and call: helper_method :my_method from the controller. 回答2: You can put a method in a controller and then call

Rails 3.2 f.file_field causes routing error

狂风中的少年 提交于 2019-12-07 16:48:48
问题 Tested on rails 3.2.12 and 3.2.11. In another rails 3.2.11 project I do not have this issue with f.file_field , but in current one I do and can't find a reason for this strange behaviour, so here is my question. I have a weird problem with update action. Here are relevant parts of code: routes: get "signup" => "users#new", :as => "signup" get "profile" => "users#profile", :as => "profile" resources :users do member do get :activate end end controller: def update @user = User.find(params[:id])