similar to: How to use group in nested associations

Displaying 20 results from an estimated 400 matches similar to: "How to use group in nested associations"

2013 Mar 25
1
validates presence of foreign key fails in nested form
I''m using accepts_nested_attributes as follows: class Timesheet < ActiveRecord::Base attr_accessible :status, :user_id, :start_date, :end_date, :activities_attributes has_many :activities, dependent: :destroy has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true end class Activity < ActiveRecord::Base attr_accessible
2013 Mar 04
2
accepts_nested_attributes: undefined method 'association'_attributes
I have 2 models Timesheet and TimeEntry: class Timesheet < ActiveRecord::Base attr_accessible :status, :user_id, :time_entries_attributes has_many :time_entries, dependent: :destroy accepts_nested_attributes_for :time_entries, :reject_if => proc { |attributes| attributes[''worktime''].blank? } end class TimeEntry < ActiveRecord::Base attr_accessible :task_id,
2013 Mar 26
0
nested forms: use validate :some_method works in update mode only
I have a strange behavior when validating a record in a nested form. The association collection is empty when creating a new record and the validation does not catch the error. But when updating the same record the validation gets it right but continues to catch the error even after modifying the needed attribute value to make it pass. Here is the model: #timesheet.rb class Timesheet <
2013 Mar 04
0
fields_for with accepts_nested_attributes: how to pass a value to a label
I can''t figure out how to pass a value from the following object build in the controller: class TimesheetsController < AC ... def new @timesheet = current_user.timesheets.new now = Date.today #generating 7 time entries: monday through sunday (now.beginning_of_week..now.end_of_week).step { |date| @timesheet.time_entries.build(:workdate; date) end end ... In the
2006 Mar 01
1
Eager loading problem. Help greately appreciated
Each Timesheet has an employee. An employee has a division and a location. I want to find all the timesheets with a status of 2. I then iterate over the timesheet collection and print the timesheet name, employee name, employee divison name, and employee location name. Like so: for t in Timesheet.find(:all,:conditions=>"status=2",:include=>:employee) puts timesheet.date
2006 Jul 12
6
Showing rows on a page
This is my first rails program and I?m having trouble figuring out how to show rows on the page when there may not be rows in the database. There are 3 tables, employees, cost_codes and timesheet, I will simplify them when describing them later on. When an employee logs in, I would like to pull up their timesheet, which should consist of one row per cost code. So timesheet would look a
2006 Mar 28
2
Fastest way of adding " " around multiline text in RADRAILS
lets say i have the following SQL in my database editor : When i paste it into rad rails i have to add quotes and the ''+'' symbol to the end of each line. It is very tedious. What is the best method? select timesheets.employee, sum(items.hours) as hours, sum(items.hours*timesheets.cost) as cost, sum(items.hours*timesheets.charge*decode(activities.chargetype,0,1,0)) as charge,
2006 Jan 19
2
select vs. select_tag
I have a "Users" object and a "Timesheets" object. Each timesheet entry belongs to a User, which is selected from a drop-down list. The timesheet has a user_id field. (The user needs to have an option to select a different user due to the way our system works.) If i use the "select" object, which is bound to the Timesheet model, using this code: &lt;%= select
2006 Aug 04
5
query across tables
I am trying to do things the proper rails way and use the auto generated id to refernce other tables. Now I''ve hit a wall in trying to write a query. timesheets: id, employee_id, code_id, ... values codes: id, job_number, code How can I show just the timesheets that belong to a specific job? I would need to check the codes table and look at the jobs, so I was thinking of something
2007 Aug 04
2
Problems using "lm" in combination with "predict"
Hello everybody, I'm trying to predict a linear regression model but it does not work. My Model: y = Worktime + Vacation + Illnes + Bankholidays My modelmatrix is of dimension 28x4 Then I want to make use of the function predict because there confidence.intervals are include. My idea was: mod <- lm(y~Worktime+Vacation+Illnes+Bankholidays) newdate=data.frame(x=c(324,123,0.9,0.1))
2006 Jul 31
1
Adding new rows to a db
I''ve created the following function, and for testing have hardcoded the following values: def addNewRow @timesheet = Timesheet.find(:employee_id => ''1'', :cost_code_id => ''14'', :dept => ''007'', :ending_date =>
2007 May 16
2
very odd controller spec problem
Here''s a snippet: it "should provide the fund" do get(:timesheet,{:id=>@fund.id}) assigns[:fund].should == @fund end Works fine on my box, fails on my CI server. Here''s the output: NoMethodError in ''The FundController timesheet should provide the fund'' You have a nil object when you didn''t expect it! You might have
2005 Sep 28
0
search engine, select the selected option
hey, i have a search engine that let u search on the an employee how can i make that if the user select "employee1" , on the next page "employee1" is selected this is my code (rhtml) <tr> <td><label for="employee_id">Employee</label></td> <td colspan="3"><%= select "employee", "id",
2009 Mar 10
5
onsubmit for remote_form_for not working properly
I want to use onsubmit for a form validation using javascript on remote_form_for for this i am doing something like this <% remote_form_for :timesheet, @timesheet, :url =>{:action => ''report_user''}, :html => {:onsubmit=>"return ValidateDate();" } do |f| %> // Form elements here <% end %> but it not works well. if condition return false
2006 May 03
1
Nubee Fixtures + Tests problem
According to the book, @timesheets["first_timesheet"] should be accesible from within my functional test, but its not! Timesheets.yml : first_timesheet: status: 2 start_date: 2006-04-24 cost: 10 employee: 444 id: 10683 charge: 20 My Test : class AdminTimesheetsControllerTest < Test::Unit::TestCase fixtures :timesheets def test_viewTimesheet get
2006 Mar 08
3
getting holiday dates?
Hi, i''m writing a timesheet application in which i need to know when the holidays are, (bank holidays, etc) Is there a very clever way of getting this info that wouldnt require me to manually add it to my database?? Thanks Chris -- Posted via http://www.ruby-forum.com/.
2005 Oct 17
4
How to send excel file to browser (spreadsheat 0.3.2)
hey, i want to generate an excel file and send it directly to the browser (without storing it to the harddisk). does anyone has any solution? thanks in advance this is my code: -------------------- def export_excel if @request.env[''HTTP_USER_AGENT''] =~ /msie/i @headers[''Pragma''] = '''' @headers[''Cache-Control''] =
2013 Feb 06
0
inverse_of breaks for unsaved child associations during save of parent
I''m willing to write a patch for this issue: https://github.com/rails/rails/issues/8893 But want to confirm that the new behavior makes sense before I make the effort. Essentially if you have an unsaved parent and child, and the parent''s association to the child has an inverse_of declared on it. When the parent gets saved, it updates the foreign key on the child, and this
2006 May 08
10
Apache 2.2, ProxyPass and HTTPS
Hi all, I''m currently trying to get Mongrel running my app whilst fronted by apache 2.2 in a sub-directory via https. A bit convoluted I''ll grant you but necessitated by existing systems. The pertinent parts of my httpd.conf: <VirtualHost 123.123.123.123:12345> #historic choice of random port number DocumentRoot /var/www/admin ServerName admin.example.com:12345
2006 Apr 24
7
Can you improve on this code?
# File app/models/timesheet.rb, line 27 27: def totals 28: totals = Hash.new 29: totals["Monday"] = totals["Tuesday"] = totals["Wednesday"] = totals["Thursday"] = totals["Friday"] = totals["Saturday"] = totals["Sunday"] = totals["Totals"]=0 #initialise all to zero 31: 32: for item in