ruby-on-rails-3.2

PostgreSQL Permission denied Error on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432” - Lion Server 10.7.3 or Lion Server 10.7.4

亡梦爱人 提交于 2019-11-28 14:16:35
I recently had major permission problems using Lion Server where permissions would change on folders at will. During this time I had started getting the following error when trying to do a rake db:migrate command: rake aborted! could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? This had been working before when I first created a Rails 3.2.3 application while running 10.7.2. All of a sudden I started having this error come up. I read many blogs about this error and tried to remove it but

How can I iterate through a MySQL result set?

天涯浪子 提交于 2019-11-28 10:59:01
Here is the code I'm using: # Run the query against the database defined in .yml file. # This is a Mysql::result object - http://www.tmtm.org/en/mysql/ruby/ @results = ActiveRecord::Base.connection.execute(@sql_query) In my View, here's what I do to see the values: <pre><%= debug @results %></pre> Outputs: #<Mysql2::Result:0x007f31849a1fc0> <% @results.each do |val| %> <%= val %> <% end %> Outputs: ["asdfasdf", 23, "qwefqwef"] ["sdfgdsf", 23, "asdfasdfasdf"] So imagine I query something like select * from Person , and that returns a result set such as: ID Name Age 1 Sergio 22 2 Lazlow 28 3

Mongoid Group By or MongoDb group by in rails

时光怂恿深爱的人放手 提交于 2019-11-28 10:31:35
I have a mongo table that has statistical data like the following.... course_id status which is a string, played or completed and timestamp information using Mongoid's Timestamping feature so my class is as follows... class Statistic include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paranoia field :course_id, type: Integer field :status, type: String # currently this is either play or complete I want to get a daily count of total # of plays for a course. So for example... 8/1/12 had 2 plays, 8/2/12 had 6 plays. Etc. I would therefore be using the created_at timestamp field

Ruby on Rails: Order users based on average ratings with most reviews?

拈花ヽ惹草 提交于 2019-11-28 09:59:19
问题 I'm able to display the items and their reviews that are within the shop. How do I get the top items with most reviews? My reviews are in another database table than shop and item. Controller @shop = Shop.find(params[:id]) @item = Item.where(:shop_name => @shop.name) View <% @item.each do |u| %> <%= u.reviews.average('rating') %> <%= u.reviews.count %> <% end %> Is there an easy method where I can order based on the highest rating with most reviews or something? Or maybe its better to

Status of Rails' link_to_function deprecation?

左心房为你撑大大i 提交于 2019-11-28 09:02:14
What is the status of the link_to_function Javascript helper in Rails? I read, including in this stackoverflow question , that it was deprecated in Rails 3.0, then undeprecated, then deprecated again in 3.2.4. Is it something I can depend on and teach students? I just read the release notes (from a search) for Rails 3.2.8 : Reverted the deprecation of button_to_function and link_to_function helpers. Rafael Mendonça França Where does this stand now? link_to_function is NOT deprecated in 3-2-stable branch and it won't be deprecated in 3-2-stable in future. But it IS depreacated in current master

Rails 3.2 undefined method `key?' for nil:NilClass

和自甴很熟 提交于 2019-11-28 08:12:29
For some reason I started to get this error after switching to Rails 3.2. I guess it has something to do with acl9 plugin, which I tried reinstalling, but nothing changed. I moved the plugins to lib/plugins and added initializer to config/initializers but again, same error. I looked for solution at acl9 repo on Github, but could not find anything there. Maybe it is not acl9 after all. I have paperclip, acl9, authlogic installed. NoMethodError (undefined method `key?' for nil:NilClass): actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?' actionpack (3.2.1) lib

How to use dependent: :destroy in rails?

↘锁芯ラ 提交于 2019-11-28 07:22:06
I have 2 models as describes below. class EmpGroup < ActiveRecord::Base belongs_to :user has_many :emp_group_members, dependent: :destroy end and class EmpGroupMember < ActiveRecord::Base belongs_to :emp_group belongs_to :user end now the problem is whenever I tried to destroy a group then I received a error as below. PG::ForeignKeyViolation: ERROR: update or delete on table "emp_groups" violates foreign key constraint "fk_rails_bd68440021" on table "emp_group_members" DETAIL: Key (id)=(1) is still referenced from table "emp_group_members". What I'm missing? Umar Khan Add cascading delete to

Override “show” resource route in Rails

╄→尐↘猪︶ㄣ 提交于 2019-11-28 07:21:14
问题 resources :some_resource That is, there is a route /some_resource/:id In fact, :id for some_resource will always be stored in session, so I want to override the path /some_resource/:id with /some_resource/my . Or I want to override it with /some_resource/ and remove the path GET /some_resource/ for index action. How can I reach these two goals? 回答1: In your routes.rb put: get "some_resource" => "some_resource#show" before the line resources :some_resource Then rails will pick up your "get"

what is the difference between link_to, redirect_to, and render?

旧城冷巷雨未停 提交于 2019-11-28 07:16:29
I am confused about the main difference(s) among link_to , redirect_to and render in Rails. anyone can please explain. link_to is used in your view, and generates html code for a link <%= link_to "Google", "http://google.com" %> This will generate in your view the following html <a href="http://google.com">Google</a> redirect_to and render are used in your controller to reply to a request. redirect_to will simply redirect the request to a new URL, if in your controller you add redirect_to "http://google.com" anyone accessing your page will effectively be redirected to Google render can be used

Rails/ActiveRecord sort by particular value

与世无争的帅哥 提交于 2019-11-28 06:25:05
问题 Is there any convenient way in Rails 3.2 to order an ActiveRecord relation by moving records with a particular value for a particular field to the front of the relation? For instance, if MyModel has an attribute country , I would like to sort relations returned by any query with records having country='Spain' to the front of the relation. 回答1: Something like this. Obviously 'name, id' would depend on your model and requirements. MyModel.order("country = 'Spain' DESC, name, id") 来源: https:/