ruby-on-rails-3

Creating has_many association with ancestry gem

倖福魔咒の 提交于 2019-12-23 04:26:56
问题 I installed ancestry gem & create Location Structure. Alaska California Los Angeles Fresno Cincotta (Fresno) Hammond (Fresno) Melvin (Fresno) Melvin 1 Melvin 2 Melvin 3 Arizona Colorado My post and location model class Location < ActiveRecord::Base include Tree has_many :posts end class Post < ActiveRecord::Base belongs_to :location end When i am add new post, how to display only depth 4 level ( Melvin 1,Melvin 2,Melvin 3 ) as drop down. 回答1: You have to enable cache depth so you can use at

new action trying to use show

試著忘記壹切 提交于 2019-12-23 04:26:54
问题 Here are my routes: equipment_index GET /equipment(.:format) {:action=>"index", :controller=>"equipment"} POST /equipment(.:format) {:action=>"create", :controller=>"equipment"} new_equipment GET /equipment/new(.:format) {:action=>"new", :controller=>"equipment"} edit_equipment GET /equipment/:id/edit(.:format) {:action=>"edit", :controller=>"equipment"} equipment GET /equipment/:id(.:format) {:action=>"show", :controller=>"equipment"} PUT /equipment/:id(.:format) {:action=>"update",

Rails Dynamically Changing Collection Select In Form Based on form field

喜夏-厌秋 提交于 2019-12-23 04:23:06
问题 I have a Rails 3.2.14 app that tracks calls and each call has a pickup and dropoff facility from the Facility model which is an association. In the call model there is an association for the Region model (i.e. Houston, Dallas, Austin, etc) where we select a region based on where the call is coming from. What I'd like to do is be able to select a specific region (i.e. Houston) and in the pickup facility collection only show Houston region facilities. I'm assuming to start off with I'd need to

thinking sphinx error when rake thinking_sphinx:start

筅森魡賤 提交于 2019-12-23 04:17:15
问题 I am using gem 'thinking-sphinx', '2.0.10' for search functionality.I am following http://railscasts.com/episodes/120-thinking-sphinx tutorial for this. script/plugin install git://github.com/freelancing-god/thinking-sphinx.git rake thinking_sphinx:index These 2 steps executed without any problem,but when i did rake thinking_sphinx:start it was giving following error : Failed to start searchd daemon. Check /home/user/newsvn/alumnicell/log/searchd.log. Failed to start searchd daemon. Check

Problem with datetime_select helper

我只是一个虾纸丫 提交于 2019-12-23 04:11:34
问题 I need some help, this is my code: <%= f.datetime_select :date, :start_year => 2011 %> When I write like this in my app, i get the time now, i want to get the time now in the month and the day selects and I want in the hour and minute selects not to get the hour and the minute now i want to see "hour" and "minute" string in the selects... So i wrote this code: <%= f.datetime_select :date, :start_year => 2011, :prompt => { :hour => "Hour", :minute => "minute" } %> In the code above, the hour

Rails WillPaginate::Collection not paginating Array

一笑奈何 提交于 2019-12-23 04:08:42
问题 An existing array vparray is being generated, then sorted by a non-db column rate . It then needs to be paginated : @vps = vparray.sort_by{|e| e.rate} @vps = WillPaginate::Collection.create(1, 10, @vps.length) do |pager| pager.replace @vps end The view; <%= will_paginate @vps, :previous_label => "prev ", :next_label => " next" -%> renders fine, the number of pages pans out and the page is apparently the first. However, upon: <% @vps.each do |product| %> , the entire sorted array is being

Translating mongoid to german

試著忘記壹切 提交于 2019-12-23 04:08:33
问题 I got a problem to translate the default validation messages in mongoid. I create a /config/initializers/mongoid.rb with Mongoid.add_language("de") http://mongoid.org/docs/installation/languages.html But every call on a validated field i got translation errors: translation missing: de.mongoid.errors.models.comment.attributes.body.too_short translation missing: de.mongoid.errors.models.user.attributes.username.blank I have Ruy on Rails 3.2 Ruby 1.9.3 mongoid 2.4.7 回答1: If you check on Mongoid

ActiveRecord querying a tree structure efficiently

大城市里の小女人 提交于 2019-12-23 04:04:30
问题 I have inherited a Rails 3 app that stores much of it's data as a fairly sophisticated tree structure. The application works pretty well in general but we are noticing some problems with performance, mostly around database interactions. I am seeing a lot of queries along the lines of these showing up in my logs: SELECT `messages`.* FROM `messages` WHERE `messages`.`context_type` = 'Node' AND `messages`.`context_id` IN (153740, 153741, /* about a thousand records... */ 154837, 154838, 154839,

Rails - Presenting complex data view

你离开我真会死。 提交于 2019-12-23 03:59:07
问题 This should be something simple but I've been at it for a day now and can't see a clear answer. I have three basic models: User, Evaluation and Job. Users work on the job and the job owner evaluates the users. A user can have many various jobs. Each job will evaluate its related users multiple times (within the job, each related user will have the same evaluations - with different scores, of course.) So, simply, I would like to present the data in tabular form (kind of like an excel workbook)

Rails - Id can't be found in Forms

北城以北 提交于 2019-12-23 03:39:08
问题 Have some time I'm stuck in this problem. I'm trying to pass 3 Id's through a form to save the data in my database. def new @person = Person.find(params[:person]) @honored = Person.find(params[:honored]) @group = Group.find(params[:group_id]) @honor = Honor.new end def create @person = Person.find(current_person) @honor = Honor.create(:group => Group.find(params[:group_id]), :person => Person.find(params[:person]), :honored => Person.find(params[:honored])) if @honor.valid? flash[:success] =