Displaying 20 results from an estimated 600 matches similar to: "How to make a drop-down automatically submit an AJAX form"
2006 Mar 15
2
Using form_remote_tag, setting the form name
I''m using form_remote_tag like this:
<%= form_remote_tag \
:update => "div_id_dataentry_bottom_ajax",
:loading => "document.getElementById(''wait'').innerHTML=''Loading...'';",
:url => { :action => "dataentry_bottom_edit" } %>
And it makes this code:
<form
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 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
2006 Mar 22
0
Another Problem with params
I am trying to do a similar thing for some spares that I am trying to manage...
My spare.rb file is as under
class Spare < ActiveRecord::Base
belongs_to :department, :class_name => ''department'', :foreign_key
=> ''department_id''
belongs_to :subequipment, class_name => ''subequipment'',
:foreign_key =>
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 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 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`
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 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
2005 Dec 19
3
Trying to make an app helper
Any ideas with fixing this? Doesn''t work properly, although it doesn''t
throw any runtime errors.
# Methods added to this helper will be available to all templates in the
application.
module ApplicationHelper
def options_for_months(selected_month)
2005 Dec 19
3
Where to put code - app controller, or app helper?
I have a function i want to be used in both views and controllers:
def year_to_fiscal_year(year)
# converts, say, an integer 2003 into ''0304''
year.to_s[2,2] << (year+1).to_s[2,2]
end
Where should i put it ?
--
Posted via http://www.ruby-forum.com/.
2005 Dec 20
2
Designing a data-entry screen
Here''s what i''m trying to do:
Have 3 dropdowns up the top of a page, being: year, month, department,
and group. Also a button underneath that called refresh.
When you click refresh, it finds the 1 row of data from the database for
that year/month/dept/group and populates the fields into a set of
textboxes below.
Then you can edit what is in those textboxes, and click a
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
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 Mar 30
3
Model.find(:all) where Model.association has more then 0 items?
Hi everyone,
I have a Department model that has_many people. How do I go about
finding all departments with more than 0 people?
Department.find(:all, :conditions => Department.people.size > 0)
That, of course, doesn''t work, but it was as close as I could come.
Thanks!
Sean
2006 Mar 13
7
Problem with params
I''ve got a User model, which holds the following (excerpt):
def try_to_authenticate
User.authenticate(self.username, self.password)
end
..
private
def self.hash_password(password)
Digest::SHA1.hexdigest(password)
end
def self.authenticate(username, password)
@user = User.find(:all, :conditions => ["username = ? AND
password = ?",
2006 Apr 10
1
random | in join statement with more than one :include
I have an ActiveRecord class that has several has_many,belongs_to,
habtm, and the new has_many => :through relationships.
Whenever I try a
find(:all, :conditions => "some conds", :include [:relationship])
it works fine, but if I have
find(:all, :conditions => "some conds", :include [:relationship,
:other_relation])
it gets a sql error such as
Mysql::Error: You