Displaying 20 results from an estimated 500 matches similar to: "HABTM: deleting records based on attributes"
2006 Jan 02
5
DB Modelling the Rails way - Opinions??
Hi,
I''m trying to figure the most efficient way to model the following. I
can think of at least two ways to relate the tables but from a
client/server perspective! I''m wondering how to best (and
elegantly)relate them from an AR perspective.
A project has many people,
A person can work on many projects at any time,
A project has many roles,
A role is performed by a person,
A
2007 Dec 09
4
Help on drying code
Hi all,
Currently I''m having to do this:
def self.authorized_roles(controller, action)
specific = self.find_by_controller_and_action(controller, action)
all_actions = self.find_by_controller_and_action(controller, ''*'')
all_controllers = self.find_by_controller(''*'')
role_ids = []
specific.each do |role_item|
role_ids <<
2006 Apr 15
6
view code regular expression
I''m lost on regular expressions to begin with...
I''m trying to fix a value to one of 4 radio buttons as there will be
value of either 1,2,3 or 4 in @roles_users...
<TD><input type="radio" id="roles"
name="case_managers[case_manager_name]"
value="Case Manager Admin"
<% if =~ @roles_users /1/ checked =
2011 Jul 14
10
Devise confusing routes
I had a similar problem yesterday.
I would go to the root of my site and I would get a Too Many Redirects
message. It seems like there was an infinite loop. After struggling for
over an hour yesterday late at night, it seemed like I fixed it.
But now, when I want to create a New User, it''s redirecting me to the
Sign In screen. Seems like I didn''t fix the problem completely.
I
2006 Jan 03
4
Would someone like to tell me why this code will not solve my problem? (it''s short)
I am building an invoicing system but cannot use the auto_increment
field to determine the invoice number (because they are running 3
different companies off the one system. I need to find the last
invoice number from any given company and then add 1 to it to get the
next invoice number. BUT, there is a unique case on the very first
invoice produced because there is no earlier invoice
2006 Apr 10
6
Single Table Mapping
This is pretty simple, but I must be missing the obvious. I''ve got a
table that''s similar to this:
USERS:
- id int
- username varchar(64)
- password varchar(64)
- role_id int
ROLES:
- id int
- description varchar(16)
I''ve had no troubles doing has_many relationships at all. But I want to
map the user.role directly to the role model automatically (which sounds
2008 Apr 03
2
Change the value stored in inheritance_column
I have been struggling for quite sometime with this.
Is there any way to configure the Model to store user defined value in
the inheritance_column instead of the default value (which is
class_name)
The problem I have is like this:
I have a User model and there are different models which inherit from
this like Admin, Premium, Professional, etc.
Each of these inherited models are identified by a
2006 Jan 21
7
n-way joins
Hi,
I''m somewhat of a Rails newbie and am trying to understand how to
formulate n-way (3 or 4 way) joins in Rails (where the join tables
contain extra data as well.)
Let me give you my basic entities:
foos
id - pk
name - unique
bars
id - pk
name - unique
bazs
id - pk
name - unique
frozs
id - pk
name - unique
then i have two separate join tables:
foos_bars_bazs - 3 way join
2007 Jan 24
2
A spec where interaction-based testing breaks down... (at least for now)
Here are the specs:
context "Finding all the stylesheets available to a company" do
setup do
@mock_company = mock("company")
@mock_company.stub!(:to_param).and_return "1"
Stylesheet.stub!(:find)
end
def do_find
Stylesheet.find_available_to @mock_company
end
specify "should convert the company into a parameter" do
2005 Sep 02
7
Form to update two tables
Hello there,
this is probably a very simple problem but I''m stuck.
I''m following the Login generator tutorial from rubyonrails. It''s all
worked fine so far. But I want to add a bit more functionality so that
when a user signs up in addition to chosing a login name and password
they type in a company name which is added to a seperate table called
COMPANIES. The id
2006 May 19
1
ActiveRecord: Minor saving problem
This is probably a very stupid error on my side, but I am doing my
first steps now and I don''t see what is wrong.
I have companies and I have users. A user can create a company. When
the user does he''s automatically a member of the company. A company
should be able to have multiple users off course so every member of a
company can add other users who don''t have a
2006 May 11
1
ActiveRecord collection_select and has_and_belongs_to_many
Hello everyone, first post to the list and a relative newbie to Rails
development. Done quite a bit of JSP, PHP, HTML, XML etc and thought I would
kick the tires on Rails to see if it can speed up development for internal
applications. Anyway, I am running into a problem that is just driving me
crazy and everything I read on the net doesn''t seem to help. I was hoping
someone here might
2009 Feb 17
3
Dynamic select box
Hi everyone,
I have a problem. I want to display a different select box wether the
current user is an admin or an user.
So I thought I could do this in my view where my form is displayed :
<p class="form-input">
<%= f.label(:role_id, ''Role:'') %>
<%
if (current_user.admin?)
then collection_select(:user, :role_id, Role.find(:all, :order =>
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
2005 Dec 19
3
Is there a list of html_options for the FormOptionsHelper?
I''m looking for a way to select a default value from a select box, like
this:
select("user", "role_id", Role.find_all.collect {|r| [ r.name, r.id ] },
{ :default_value => ''5'' }
(of course, there is no ":default_value")
If the form is being used on a ''create'' page, it should display a
default in the select box. If
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
2005 Dec 16
6
managing belongs_to fields in a form
Hi all,
I cannot find a clean way to create/edit an object that ''belongs_to''
another one, just by using form fields.
I always need to explicitely unassemble it, store the master id in a
hidden field, and then refetch the master from its id, and put it back
in the object.
To summarize:
I want to create a new member, for a given project
@project= ...
@member =
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
2009 Mar 17
1
Route failure with Rails2.3 and rspec1.2
Hello all,
I have a spec for a route 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
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,