Displaying 20 results from an estimated 100 matches similar to: "Another Problem with params"
2006 Mar 01
2
Validating that a foreign key is present and ok
How do I validate that a model object''s attribute is a valid foreign
key? The problem is, I can''t check if the attribute is a valid foreign
key if the attribute doesn''t even exist.
For example, every employee must be in a department. In the following
code, if an employee''s department_id is not present then
Department.find_by_id(department_id) might cause
2006 Nov 08
4
writing SQL query WHERE.. IN.. anArray ?
I have an array @dpt_ids
ex : @dpt_ids = ["43", "48", "49", "50", "51"]
I try to insert it into my sql query to be used in a ''find_by_sql''
query = "SELECT * , #{kms} AS km FROM cities"
query << " WHERE department_id IN ( #{dpt_ids} ) "
but this transform my array into a unique string :
2006 Mar 13
3
validates_associated problem
Hello,
I have a situation where an ''employee'' belongs to a ''department'' and
have setup the relationship as follows.
class Employee < ActiveRecord::Base
belongs_to :department, :foregin_key => "department_id"
validates_associated :department_id
end
class Department < ActiveRecord::Base
has_many :employees
def validate_on_update
2006 Feb 23
4
MySQL Duplicate Key Error
I am a newbie and I am running into a problem which I cant understand. I
have a table called ''privileges'' which has the following fields
CREATE TABLE `sdqualplanner`.`privileges` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(20) NOT NULL default '''',
`description` varchar(100) NOT NULL default '''',
`section_id`
2005 Dec 21
3
How to make a drop-down automatically submit an AJAX form
Hi,
I know that to make a dropdown box automatically submit when you change
the value, you do this:
<select ..... onchange="this.form.submit();">
BUT i''ve got an ajax form, and if i do the above trick, it simply
reloads the ajax partial into the whole screen, rather than into the div
where it is meant to go.
I''ve already got it all working so that if you click
2012 May 07
1
Complex sorting question, or not?
I have a function that displays all depts and related info from other
tables in my Department model, such as:
def dept_and_hospital
"#{name} (#{floor.building.hospital.name})"
end
... which is used in my view, like:
<p>
<%= f.label :department_id %><br />
<%= collection_select(:device, :department_id, Department.all(),
:id, :dept_and_hospital,
2006 Mar 12
3
Newbie: using find like a sql join query
I have a working Rails app with several related tables, but can''t find
an answer to this question in the Dave Thomas Rails book. Imagine for
example:
table departments with columns: id, department_name
table employees with columns: id, department_id, employee_name
and of course the employees table has a constraint foreign key
(department_id) references departments(id)
So this is
2006 Aug 03
0
autocomplete and one to many relationships
Hello,
I am trying to get autocomplete to save record ID.
I have to tables:
Students and Departments.
Students table has department_id field.
Department table has 2 fields: id and name
I set up belongs_to: andÂ
has_many: entries in the models of each.
In my _form.rhtml I have the autocomplete line that is working:
<%= text_field_with_auto_complete :department, :name %>
ie.
2006 Aug 04
0
Fwd: autocomplete and one to many relationships
Hello,
I am trying to get autocomplete to save record ID.
I have to tables:
Students and Departments.
Students table has department_id field.
Department table has 2 fields: id and name
I set up belongs_to: andÂ
has_many: entries in the models of each.
In my _form.rhtml I have the autocomplete line that is working:
<%= text_field_with_auto_complete :department, :name %>
ie.
2005 Dec 23
0
Problem with large join table and ActiveRecord
Hello,
I''m having a hard time explaining this, so I hope i can say this
correctly. I have these tables:
people
id
fname
lname
departments
id
name
buildings
id
name
room
wtkeys
id
key_number
key_way
Issued_keys
id
people_id
department_id
building_id
wtkey_id
date_issued
My
2006 Apr 26
2
two layers of has_many
Hi,
There are many companies. Each company has many departments. Each
department has many employees. The following find_by_sql method seems
awful. What is the best way to get all the employees of a company?
class Company < ActiveRecord::Base
has_many :departments
def employees
Employee.find_by_sql("SELECT employees.*
FROM companies, departments, employees
2007 Jul 09
3
NoMethodError when using find_by_sql
I''m try to verify users on login. Here is my code:
def self.authenticate(username,password,account_code)
employee = self.find(:all,
:select => "e.id, e.first_name, e.last_name, e.username,
e.account_id, e.department_id, o.pay_type_id, o.admin_yn, o.payroll_yn,
o.files_yn, o.dept_report_yn,e.salt, e.hashed_password",
:conditions => ["e.deleted_yn=0 and
2007 Dec 03
5
spec for model_id should eql
Hello,
I''m confused why the spec described below is failing. Other simple
comparison specs are passing fine for the same model. The code is working
accordingly when I test it through the console, I''m just having difficulty
getting this spec to work. Any pointers would be appreciated.
Failure message:
''Address fetch and geocode should extract department and write to
2006 Jul 12
0
Lookup Field ??
Hi,
I am new to Rails. And I wonder how to define lookup fields for a table...
Suppose we have an employee table and a departmant table...
Each employee record have a department_id field...
And when listing employees, we want to show the user friendly department_name from department table..
How can I do this?
Thanks ....
Bu e-posta mesaji, mesajin alici kisminda belirtilmis
2006 Jul 23
2
REST controller with up and down for model that acts_as_list
Hi,
I have the following models
class Department < ActiveRecord::Base
has_many :products
end
class Product < ActiveRecord::Base
belongs_to :department
acts_as_list :scope => :department_id''
end
When I look at a list of products for a particular department I have
up and down buttons to re-order the products. Currently my controller
is something like this
class
2006 Jan 21
0
Display options from HABTM
I have a large certifications table that I would like to have a little
more controll over, it is part of a HABTM relationship.
-----------------------------------
db''s (simplified)
>certifications
id
course
>employees
id
department_id
type_id
name
>departments
id
name
>types
id
kind
>certifications_employees
certification_id
employee_id
2010 Oct 19
0
Ajax & Table Display Filtering based on Selected Option
My scenario:
On a department''s products page (index.js.rjs), there is a table
showing the products with their id, name, category. The view of this
table is specified by a partial file called _index.html.erb. I''m
going to add in a selection/option drop down menu above the table to
show all the product categories. When the user selects a category
from the drop down menu, Ajax
2010 Aug 02
7
Complex associations
I am working on a project that has some complex table associations,
and I am having a hard time declaring this association in a Model, and
fear it can''t be done.
Here is an example of my issue...
class StoreType < ActiveRecord::Base; end
class Store < ActiveRecord::Base; end
class Department < ActiveRecord::Base; end
class Product < ActiveRecord::Base; end
A StoreType has
2006 Jan 31
6
Pagination - why is it this hard?
Hi everyone,
I''m at the end of my rope on this. I can''t get pagination to work
with anything but a standard find on a model. If I try to do a search
and customize the pagination, I get lots of different variations.
My thought was to have the list action do what it does, but to pass it
a list of search conditions from the search action. So, if search
determines that we need
2006 Apr 06
6
pagination question
i''ve figured out how to use the next and previous links with the
paginator class but now i''m trying to figure out how to display all the
page numbers in between. looking through the rails api, i found
paginator.each() but i''m not sure how to use it, or if that''s even what
i am looking for.
also, is there a way to limit the amount of pages like some sites