Displaying 20 results from an estimated 400 matches similar to: "Adding new rows to a db"
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
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 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
2008 Apr 25
2
Can't Understand Why This Works
I have 3 methods:
def add_to_cart
# do some stuff
redirect_to_index
end
def empty_cart
# do some stuff
redirect_to_index("your cart was emptied")
end
def redirect_to_index(msg = nil)
flash[:notice] = msg if msg
redirect_to :action => :index
end
How come the flash notice works if I''m setting msg = nil? For example,
if I''m in empty_cart and pass
2013 Mar 30
1
How to use group in nested associations
The below query fails:
Timesheet.joins(:time_entries).select("timesheets.*,
sum(time_entries.worktime) as total").group("timesheets.start_date")
The models have the following relations:
Timesheet < AR
has_many :activities, dependent: :destroy, inverse_of: :timesheet
has_many :time_entries, through: :activities
accepts_nested_attributes_for :activities,
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:
<%= select
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,
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,
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
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 Dec 22
7
Ruby on Rails and lookup tables
Hi,
I''m a newbie on both Ruby and Ruby on Rails, and I''m struggling with
my first app. I have a table with a column called "employee_id" which
is a foreing key associating it with the "employees" table. I have
populated both tables.
When I run "ruby script/generate scaffold <model name> <controller>"
it generates a web page with all
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
2007 Oct 25
1
find - group - postgres
I am not sure that this is entirely a rails question as I am trying to
run the command in postgres and I am getting the same error...
controller code...
@client_slot_count = ClientSlotsDaily.find(:all,
:conditions => ["created_at > ? AND created_at < ? AND
facility_id = ? AND client_id IS NOT NULL",
starting_date, ending_date, @facility.id],
2010 Jul 22
2
p-VALUE calculation
Here is my dataframe with 1000 rows:
employee_id weigth p-value
100 150
101 200
102 300
103 180
.....
My question:
how can I calculate the p-value in R for each employee? the
distribution of the weigth will be established from the above 1000 samples.
--
View this message in context:
2006 Mar 24
6
login forms , redirect_to and ajax-scaffold problems
Hi,
I have a standard type authentication technique direct from AWDWR, so there is a
before_filter :authorize_employee, :except => :login in my employees_controller.rb
the authorize_employee is in application.rb
def authorize_employee
unless session[:employee_id]
flash[:notice] = "Please log in"
# save the URL the user requested so we can hop
2008 Apr 21
1
Urgent ActiveRecord has_many Problem - Please Help
Hi Guys,
I''ve been looking everywhere for an answer to this but so far without
success.
I have three models:
1) employees
has_many :memberships
has_many :projects, :through => :membership
2) projects
has_many :memberships
has_many :employees, :through => :membership
3) membership
belongs_to :employees
belongs_to :projects
Membership is used to join employees
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/.
2007 Jul 26
1
Bi-directional self-referential HABTM
Hi,
I''m having a little trouble figuring out how to make a self-
referential HABTM bi-directional.
I have a Employee class. Each employee can have a couple of bosses,
who are also employees. The employee class has the following HABTM:
has_and_belongs_to_many :bosses, :class_name =>
"Employee", :join_table => "bosses_courses", :association_foreign_key
=>
2006 May 20
3
In a find, can''t you use both :include and :limit ?
I''m trying to do a find that includes a join. It has to be a find
because I''m using the results for a Pagination, so I need to limit my
query to the number of results I want to display per page.
Here''s the type of thing I want to do:
Employee table <-> Skills_Employees table <-> Skills table
Let''s say I want to find all the employees who have
2007 Feb 13
1
Passing Arrays in recursive functions.
ok, I''m still new to ruby and new to rails. what I have is a task
database that acts_as_tree a task can have a children an those
children are full tasks so they can have children of their own, Tasks
can only be completed if they have no children, a task with children
is only completed if all its children are done. this much I have
working, I''m trying to add some Ajax support for