Displaying 20 results from an estimated 59 matches for "company_id".
2006 Jan 03
4
Would someone like to tell me why this code will not solve my problem? (it''s short)
...se there is no earlier invoice number. My
solution is as follows (and does not work)
This is in the ''create'' controller
if Invoice.find(:all)
@temp = Invoice.find_by_sql("select max(inv_number) as inv_number
from invoices where company_id = params
[:company_id")
@invoice.inv_number = @temp[0].inv_number +1
else
@invoice.inv_number=1
end
The error I am getting is
NoMethodError in Invoices#create
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
T...
2006 May 19
1
ActiveRecord: Minor saving problem
...any
should be able to have multiple users off course so every member of a
company can add other users who don''t have a company yet. This last
step is what I am trying to implement now.
The function in the controller:
def invite
@invite_user=User.find(:first, :conditions => ["company_id = 0 AND
id = ?", params[:id]])
if @invite_user
@invite_user.company_id = @session[:user].company_id
@invite_user.save
flash[:notice] = "User #{@invite_user.real_name} was
successfully added to your company #{@invite_user.company_id}"
else
flash[:notice...
2007 Jan 24
2
A spec where interaction-based testing breaks down... (at least for now)
...convert the company into a parameter" do
@mock_company.should_receive(:to_param).and_return "1"
do_find
end
specify "should find stylesheets belonging to only the company or to
nobody" do
Stylesheet.should_receive(:find).with(:all, :conditions =>
["company_id IS NULL OR company_id=?", "1"])
do_find
end
end
And here''s the code:
class Stylesheet < ActiveRecord::Base
def self.find_available_to(company)
find :all, :conditions => ["company_id IS NULL OR company_id=?",
company.to_param]
end
end
You can s...
2005 Sep 02
7
Form to update two tables
...t;Signup »" class="primary" />
<%= end_form_tag %>
ACCOUNT_CONTROLLER.RB
--------------------
....
def signup
@user = User.new(@params[:user])
@companies = Company.new(@params[:company])
if @request.post? and @user.save
@user.company_id= @companies.id #
@session[:user] = User.authenticate(@user.login,
@params[:user][:password])
flash[''notice''] = "Signup successful"
redirect_back_or_default :action => "welcome"
end
end
table COMPANIES
---------------...
2005 Nov 16
1
HABTM: deleting records based on attributes
...e_id =>
params[:role_id])
So I make 2 entries for a Company. One with the role of ''shipping'', and
one with the role of ''distribution''. Now how do I remove only one of
the entries? I can only seem to find ways to remove Companies from a
Project based on company_id (which deletes both entries).
@project.companies.delete(company)
I need to be able to do it based on company_id and role_id.
Here are my models:
class Company < ActiveRecord::Base
has_and_belongs_to_many :projects
belongs_to :role
end
class Project < ActiveRecord::Base...
2006 Aug 14
6
Testing fails with fixtures not when invoked directly
...s :organizations
def setup
@smo = organizations(:smo)
end
def test_department_company_defaults_to_parent
org = Department.new(:name => ''company'',:cost_code => ''123'', :parent_id
=> organizations(:root_dept))
assert org.valid?
assert org.company_id = organizations(:root_dept).company_id
end
end
This fails when loading the fixtures file from rake but works if I do the
test by itself
ruby test/unit/test_organization.rb => this works
rake => fails
D:\workspace\directory>rake
(in D:/workspace/directory)
c:/ruby/bin/ruby -Ilib;tes...
2009 Mar 17
1
Route failure with Rails2.3 and rspec1.2
...that used to pass under Rails 2.2.2 and rspec
1.1.12, but can?t figure out what is wrong since I updated. Here is the
assertion:
route_for(
{
:controller => ''purchase_orders'',
:action => ''update'',
:company_id => "32",
:id => ''1''
}).should == "/companies/32/purchase_orders/1"
Which results in this failure
Test::Unit::AssertionFailedError in ''PurchaseOrdersController route
generation routes #update to /compani...
2005 Dec 31
7
Dynamic form? Not really!
Hi guru''s out there,
Im happilly coding my first rails app, and all goes well. I find myself
manually coding in a particular field all the time (company_id), that relates
the contact to a company. The total coding of this form seems somewhat much.
Could somebody tell me what Rails power I''m possibly missing and stuborn as I
am trying to do myself?
I was wondering if the first part of the form can simply be put in the loop
somehow and sti...
2005 Oct 26
1
Re: collection_select question about selected_value
Paul Welty wrote:
> collection_select(:client, :company_id, @companies, :id, :name, {
> :selected_value => 2 , :prompt => "Please select a company..." })
>
> Returns a functioning SELECT element, but it won¹t select the second item.
> (BTW, using the selected_value as a string doesn¹t work either)
>
> Am I doing somethin...
2005 Jan 24
1
.call file creation
I am curious partly because it has occurred randomly in my asterisk
system. How does one go about creating a .call file for placing a call
between two extensions/phones? I know this has been mentioned and is
probably in one of the wikis somewhere, but I am unsure exactally how to
go about doing it. Can anyone point me in the right direction.
Dan
2012 Jun 08
7
filter children with acts_as_tree
Hello Experts,
I have a tree of categories in this category object there is a property
called type.
the root categories have no type but the children have. so how I can get
all the roots with filled in children that have category type = ''B'' for
instance.
I tried to run Category.roots then delete children With a category not
equal to ''B'' but this causes a major
2007 Nov 21
7
describe AddressesController, "handling GET /addresses" do
...troller I have:
before_filter :get_company
def index
@addresses = @company.addresses.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @addresses }
end
end
private
def get_company
@company = Company.find_by_id(params[:company_id])
end
My controller spec code for handling GET /addresses:
before do
@company = mock_model(Company)
@addresses = mock("addresses")
@company.stub!(:addresses).and_return(@addresses)
Company.stub!(:find).and_return(@company)
end
def do_get
get :index, :compa...
2006 Jan 26
1
Transactions for multiple models
I have users and companies tables where users belongs_to companies.
def signup
@company = Company.new(params[:company])
@user = User.new(params[:company])
@user.company = @company
if @user.valid? and @company.valid?
@company.save
@user.save
end
end
How can I make this into a transaction? Is this a candidate for a
distributed transaction?
If so, from what I understand from the API,
2005 Aug 19
2
data validation
I''m trying validate date before they''re stored into the DB, but it seems,
validation doesn''t work..
my model looks like this:
class Company < ActiveRecord::Base
has_many :contacts,
:foreign_key =>''company_id''
has_and_belongs_to_many :categories, :join_table => ''company_to_category'',
:foreign_key => ''company_id'',
:association_foreign_key => ''category_id''
validates_presence_of :name
validates_uniqueness_of :name...
2006 Aug 14
1
Rest, routes, path_prefix and default params
...quot;action"=>"index", "controller"=>"departments"}
How can I use restful routes with default parameters?
***** routes.rb *******
ActionController::Routing::Routes.draw do |map|
map.resources :departments, :path_prefix => ''mycompany'',:company_id => 1
map.resources :companies do |companies|
companies.resources :departments do |departments|
departments.resources :departments, :name_prefix => ''child_''
end
end
# Install the default route as the lowest priority.
map.home '''', :controller =...
2006 Mar 30
6
MS SQL query strangeness for ActiveRecord in Rails
...sting based upon the value chosen from the drop down
list. In the controller, I used find() method but with customized
parameters such as the following:
<pre>
Member.find(
:all,
:select => "members.id as id, members.last_name,
members.first_name, members.phone, members.company_id, companies.name",
:order => @sort,
:joins => ", companies, engagements_members, engagements",
:conditions => [@cond_str] + @cond_params,
:limit => @user.rows_per_page,
:group => ''members.id, members.last_name, members.first_name,...
2005 Dec 22
3
foreign_key setting ignored
...e following line to views/company/show.rhtml to
try and get at the child elements...
<%= debug(@company.contact) %>
I''ve tried loads of variations on this setup, but always end up with an
error along the lines of...
|"invalid identifier: SELECT * FROM contact WHERE (contact.company_id = 100011847)"
|Rails appears to be ignoring the foreign_key setting in contact.rb and attempts to use company_id instead of companyid. Can anyone suggest what''s wrong with this setup?
Thanks in advance for your help,
Derek
2007 Apr 04
2
[PLUGIN] ArPaginator - Allows you to easily paginate over any existing AR queries.
...n is fairly limited...you pass in the
model name, and optionally some conditions, and it generates a
paginated query for you. This gets to be very bad if you''ve got any
custom queries.
class Company < ActiveRecord::Base
def complete_videos
Video.find :all, :conditions => "company_id=#{id} AND
status=''complete''", :order => "created_at DESC"
end
end
You wouldn''t be able to easily paginate over that query. You''d end up
doing something like this in your controller:
@video_pages, @videos = paginate :users, :conditions =>...
2006 May 23
0
RJS replace adding multiple inputs
...oblem. I want to replace a hidden field inside a
form with a hidden field with some value when a link_to_remote is
pressed. In the link''s action rjs, I''m doing the following:
Assume my form has the following field already
<%= hidden_field(''client'', ''company_id'') $>
So I have a bunch of companies in a list with link_to_remote tags to
action select_company.rjs inside which I want:
page.replace "client_company_id", hidden_field("client", "company_id", :
value => @company.id
But when I do this, it works bu...
2006 Apr 26
2
two layers of has_many
...od 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
WHERE companies.id=departments.company_id
AND departments.id = employees.department_id"
ORDER_BY employees.last_name)
end
end
class Department < ActiveRecord::Base
belongs_to :company
has_many :employees
end
class Employee < ActiveRecord::Base
belongs_to :department
end
I am using Rails 1.0 i...