Displaying 20 results from an estimated 1000 matches similar to: "after_create and has_one association bug?"
2009 May 27
9
Contingent Select Boxes - 2 Q's
I have a form with contingent select boxes (the state is contingent on
the country selected, so when the country selected changes, the state
changes -- I am using the Carmen plugin for getting my state names and
country names together, but not the functionality I am interested in
achieving).
Everything works fine except I cannot figure out how to amend my code
such that:
A. When the form is first
2009 May 27
12
query on Ruby array
Looking for suggestions on following two queries.
Query 1
------------------------------
Are the two following lines of code different in Ruby / Rails ( in a
*.html.erb) file.
<% if @forms.count != 0 %> <!-- first code -->
Vs.
<% if @forms.count %> <!--second code -->
@forms is an array of objects. Coming from "C" language development
background, i thought
2010 May 05
6
form remote tag :before=> function problem
Hi I have a strange problem, I am using the below code
form_remote_tag :url => ''/abc/test'',:before => "return hello();",
:update=>''test_categories'' ,:complete => "Element.hide(''spinner'')",
:loading => "Element.show(''spinner'')" do
I am using :before=> function to validate the
2009 May 05
4
modalbox rails var interpolation
Howdy everyone.
I am using modalbox which is very nice an easy to use. I have this
for an edit for a company listing:
<td><%= link_to(''Manage Companies'', {}, :onclick => ''Modalbox.show(\''/
companies/edit/#{company.id}\'', {width: 600}); return false;'') %></td>
The link is not putting the company.id in it puts #{
2009 May 25
1
Passing a JavaScript variable through a Rails params hash
Hi guys, hoping someone can give me a pointer with this?
I have a Javascript variable that I''m updating dynamically as a user
interacts with the page. I want the user to be able to save it''s value
at any time along with some text data in a pop-up form, so the best way
I can think of is to pass it through the params hash without writing it
into the form. I''m not totally
2009 May 25
2
CAn u please tell wats the prob in runnning my project?
[~/kallori]# rake db:migrate
(in /home/gm/kallori)
no such file to load -- hmac-sha1
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require''
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require''
/home/gm/kallori/vendor/rails/activesupport/lib/active_support/
dependencies.rb:510:in `require''
2009 May 24
6
belongs_to not saving foreign key
Under Rails 2.3.2 using a completely brand new project, I have 2
models:
class Author < ActiveRecord::Base
# name:string
end
class Book < ActiveRecord::Base
# title:string
belongs_to :author # author_id
end
And a simple test where i create a Book with an Author using the
belongs_to and then update the foreign key directly:
require ''test_helper''
class BookTest
2008 Apr 07
7
Saving attribute
Something is getting lost here.
def create
@home = Team.find_by_user_id(current_user.id)
for player in @home.players
player.update_attribute(:game_id, @game.id)
end
end
def show
@players = Player.find_all_by_game_id(params[:id])
end
view
<%= @players.size %> # mistakenly equals zero
Played with the console and everything should be working fine...
2009 May 05
9
no sql in the controller guideline
hello. i just checked Chad Fowler''s post "20 Rails Development No-No''s"
and
one guideline caught my attention. it says:
"Nothing that looks at all like SQL should go into a controller, view,
or helper."
it really came as a surprise to me as Rails itself seems to go against
such practice by its AR ''conditions'' option, which most of the times
2008 Apr 15
4
ActiveRecord::StatementInvalid in BlogController#index
Hello. I''m trying to do the video tutorial "how to build a blog engine
in 15 minutes with ruby on rails" from the main rubyonrails website,
and I''m getting an error when I try to use scaffold :post after
editing my config file for the mysql database.
Here is the exact error I''m getting:
ActiveRecord::StatementInvalid in BlogController#index
2008 Apr 02
9
Problem getting the most recent has_many associated object
I can''t get my view to display the most recent parameters from an
associated object in a view... here is a birds-eye of my app:
I have two models, Ferms and Kinetics. Ferm has_many :kinetics,
Kinetic belongs_to :ferm. Kinetic has the fields ferm_id, brix and
temp.
In my ferms/index view I have a table listing the attributes of each
ferm instance. I would like to display the most recent
2008 Mar 06
3
cache_sweeper
Hi,
Why is cache_sweeper not a documented method? I was pretty sure it
used to be, but I could be wrong. I can''t seem to find any
information on it anymore in the online docs.
As a side note, looking at the code for cache_sweeper it appears to
only work with the :only option, not :except (ignores it)... what''s
the reason for this?
Thanks,
Andrew
2009 Dec 20
3
Noob Install Failed 0.0.0.0:3000
Happy Holidays,
I am new to RoR and have just run through the install, which well
seemed to be vaquely documented as some ''Do this'' type of thing on
the http://rubyonrails.org/download page.
download gem
setup.rb
gem install rails
rails path/to/your/new/application
cd path/to/your/new/application
ruby script/server
and then ( drumroll ) ....
Follow the instructions on
2009 Mar 29
2
after_create and after_save
Hi,
AFAIK after_create is called after_save if the entry does not exist in
the DB.
Is there a way to tell if a specific model is new or not in
after_save?
I have to do something like:
def after_save
add_to_history ''save''
end
def after_create
add_to_history ''create''
end
However after_save is called when creating too.
--
cheers,
M.
2006 Aug 17
4
Automatically creating associated records with after_create
Hi all.
I am actually using ActiveRecord outside of Rails but I don''t see that
it matters for this question.
I want to automatically create a registration entry when I add a new
user to my application. This works fine, but it''s not automatic:
class User < ActiveRecord :: Base
has_many :registrations
end
class Test
user = User.new
user.registrations.create
end
2009 Jul 21
2
Machinist - having problems stubbing an after_create filter
Hi all
I''m moving to using Machinist in my rspec tests and am having a problem
with an after_create callback method that i need to stub out. It seems
like calling ClassName.make will trigger this callback before i''ve had
the chance to stub it.
Can i stub it in my blueprint for that class? Or, can i stub the method
for all instances of the class before i call ClassName.make?
2009 Feb 05
1
Need the activerecord-sqlserver-adapter but...
Hi... I am new to RoR development, and Web development in general (but
have about 25 years of IT/software experience - just not in the Web
area)... I have a really good RoR 2.X book that I have read and reread a
few times and starting to try to apply what I read... Have a Web app
that I need to write at work, and prove to folks that RoR is THE_WAY,
despite their ASP .NET protests otherwise...
So,
2008 May 09
5
dynamic models
Hi
In my app , a user can create a set of question then a table is
dynamily created , in the database,to store the answers of the
questions. the name of the table is answers_x (x is the id of the
questionniare).
Is it possible to dynamicly create a model, to handle the answer_x
tables ?? I can''t manually create a model then restart the server.
2008 Sep 23
3
calling save in after_create hook
Scenario:
I''m creating an image file upload service for my web site.
As well as saving the actual file I also need to create a database
record for the file.
I would like to name the file after the record id, but I also need to
save some attributes of the image (width/height/mime_type etc) which I
can''t discover until after the file is created.
The Problem:
1) The id is not
2006 Aug 14
2
after_create is not being called
Hi all
I have the following model:
class PhotoGallery < ActiveRecord::Base
attr_accessible :title, :description, :file_path, :title_photo_id
has_many :photos, :dependent => :destroy
belongs_to :title_photo,
:class_name => ''Photo'',
:foreign_key => ''title_photo_id''
validates_presence_of :title, :description, :file_path