search for: find_or_create_by_nam

Displaying 20 results from an estimated 20 matches for "find_or_create_by_nam".

Did you mean: find_or_create_by_name
2006 Apr 20
2
acts_as_taggable magic.... please explain
Hi, There is a line in acts_as_taggable plugin: send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self) could someone explain what is: send(xxx) and .on(self) I cannot find it rDoc -- Posted via http://www.ruby-forum.com/.
2006 Feb 26
5
Help On Associations Extension.
Hi to all, I''m needing some help here ... I want to do an extension on a has_and_belongs_to_many to build a custom add method to the association. i have a table locations that has a many-to-many association with a tags tabel using a locations_tags table. i want to add a method to the Location has_and_belongs_to_many association so that i can do something like this on the location
2006 May 19
0
Works in model but not in mixin
...the existing ones. On the surface this seemed easy enough and eventually I got it working. However, the following method: def add_tags(list) Tag.transaction do Tag.parse(list).each do |name| if acts_as_taggable_options[:from] send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self) else Tag.find_or_create_by_name(name).on_unique(self) end end end end Only works if placed in my model (that has the acts_as_taggable helper) or in a controller. If I place it in the acts_as_taggable.rb instance methods it doesn''t work...
2010 Dec 20
2
foreman issue
Hello! I try to use foreman. It''s successfuly import current nodes from puppet storeconfig. Nodes hostname stored in short form, without domain. After that, i run puppet on newly created additional 5 nodes. They shows in foreman with full fqdn. Os, environment, architecture for this nodes not shown. How can i fix this issue? -- You received this message because you are subscribed to
2006 Jun 25
1
Having Trouble Using ActsAsTaggable
...modifed it according to the tutorial form making it user specific (http://www.slashdotdash.net/blog/articles/2006/04/29/acts_as_taggable-per-user-tagging ). I keep getting errors when I try to tag things, however, and have traced the problem to the line of the tag_with function that calls the find_or_create_by_name function. So I fired up the console and did the following: Loading development environment. >> Tag.find_or_create_by_name("ruby rails", User.find(2)) NoMethodError: undefined method `find_or_create_by_name'' for Tag:Class from /usr/local/lib/ruby/gems/1.8/gems/a...
2006 Apr 30
0
populating model attribute from one of many lists
...uxiliary attributes (simplified version below): def before_save if not self.recent_project.nil? self.project = Project.find(self.recent_project) elsif not self.all_project.nil? self.project = Project.find(self.all_project) else self.project = Project.find_or_create_by_name(self.new_project) end end To make matter trickier, I mangle Project.name before saving new Projects. In order to make them easier to sort I move leading articles to the end of the name, e.g., "The Widget" becomes "Widget, The". This is accomplished using a before_vali...
2006 Mar 14
7
Single form w/ relationships: how do I integrate it?
...9;m creating more noise than I should. I want to know the easiest way to deal with this scenario: I have articles. I have categories for the articles. On the form where you write an article, there needs to be a free-form field to entire the category. The create() method will build the article, find_or_create_by_name the category, and assign it to the article. After that, the article is saved. I need to display an error if the category isn''t included, and I need it to act like a normal form error: add its message to the list of errors, and highlight the field. Does anyone know an easy way to do thi...
2006 Jun 07
0
Refreshing remote :through associations with deletes
Hi everyone, I''m refreshing the local Rails database from a remote database every 10 minutes. I''m using a :through association to relate people to mailinglists through subscriptions. # Works fine, every 10 minutes: remote_lists.each { |list| List.find_or_create_by_name(list.name) } remote_subscribers.each do |subscriber| person = Person.find_by_email(subscriber.user) unless person.nil? Subscription.find_or_create_by_person_id_and_mailinglist_id(person.id, local_list.id) end end remote_lists.each do |list| local_list = Mailinglist.find_or_create_by_n...
2010 Mar 11
4
Call a controller method from a view
...try to call my controller method: <%=link_to "Add",:action => :add_ingredient,:id => @product %> This is my method in the controller: def add_ingredient if @product.id.blank? @product = Product.find(params[:id]) end @product.ingredients << Ingredient.find_or_create_by_name(params[:search]) @product.update_attributes(params[:product]) end The error: Unknown action No action responded to 30. Actions: add_ingredient, create, destroy, edit, index, new, show, and update the url: http://localhost:3000/products/30/add_ingredient Thanks Greg -- Posted via http://...
2007 Sep 16
4
How far to go with ActiveRecord unit tests without hitting the database?
I''m currently try to push my limits a little bit with some of my unit testing -- trying to avoid saving ActiveRecord objects to the database and take advantage of mock/stub objects. How far should I expect to get in this direction? From what I can tell, ActiveRecord seems to fight me when it comes to associations. In other words, many associations seem to require database queries.
2006 Aug 11
1
Avoiding adding duplicates to has_many collection?
Since there''s no ''exists?'' method for a has_many collection, is there an easier way to avoid adding duplicates to a collection? (I assume obj.items << item would add duplicates if repeatedly called.) Right now I do: category = Category.find_or_create_by_name(category_name) directory.categories << [ category ] if directory.categories.find(:first, :conditions=>[''category_id=?'', category.id]).nil? YUCK. Sure would be nice if there was a ''collection#exists?(id)'' or ''collection#exists?(obj)'...
2006 Jan 05
0
Problem implementing tagging
...def tagstring=(string) self.tags = string.split.map do|t| Tag.get(t) end end end class Tag < ActiveRecord::Base validates_presence_of :name has_and_belongs_to_many :posts, :join_table => ''tagmap'', :order => ''created_at desc'' def self.get(name) Tag.find_or_create_by_name name end end -- - Mik Mifflin "Whether freedom is going to survive at all is in doubt, but we''ve got to try" - RMS -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060105/a043f181/attachme...
2005 Dec 27
1
Legacy Data without Primary Keys
...are unique, though. What''s the best practice & how''s it done pls? * Make a string id field and concatenate the two fields (or whatever I want for an ID) in it * Set the two fields to be primary keys, Rails picks it up, and don''t use find() * Manually check with find_or_create_by_name_and_date(params) for each record * Something else... Thx!
2007 Nov 29
0
has_many_polymorphs for user owned tags
...ser_id to the taggings table. Then I added belongs_to :user in the Tagging model. In the lib/tagging_extensions.rb file I added a new function: def _add_tags_from_user incoming, user taggable?(true) tag_cast_to_string(incoming).each do |tag_name| begin tag = Tag.find_or_create_by_name(tag_name) raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record? Tagging.create(:tag => tag, :taggable => self, :user_id => user.id) rescue ActiveRecord::StatementInvalid => e raise unless e.to_s =~ /duplicate/i...
2008 Dec 14
0
ActionController::TestRequest bug?
...ile starting to setup functional tests for my application I received the following error: NoMethodError: undefined method `server_name'' for #<ActionController::TestRequest which is coming from an instance variable I''m setting up in my application controller. @domain = Domain.find_or_create_by_name(request.server_name) I''m using rails 2.0.2, any guidance would be appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyo...
2009 Jun 22
0
Array unshift and save to database
Hello, I''ve noticed that I can''t save my object to the DB after using ''unshift'' on one of Array fileds. Ex: (below ''tags'' is a collection in object ''transaction'') transaction.tags.unshift(Tag.find_or_create_by_name(name)) transaction.save! Everything is fine when I am using ''<<'' to append tag to array. Regards -- Posted via http://www.ruby-forum.com/.
2010 May 05
0
Auto_complete with has_one association
...me, :birth_date serialize :newsletters has_one :ville GENDERS = %w(Homme Femme) ROLES = %w(Admin Business User) def full_name [@first_name, @last_name].join('' '') end def ville_name ville.name if ville end def ville_name=(name) self.ville = Ville.find_or_create_by_name(name) unless name.blank? end end I want to find the "ville" ID typed in the auto complete field. Greg -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this grou...
2012 Apr 09
0
Autocomplete text-field version of dynamic select menu?
...<%= link_to ''Cancel'', styles_path, :class => ''btn'' %> </div> </fieldset> <% end %> and in styles.rb (model): belongs_to :brand def brand_name brand.try(:name) end def brand_name=(name) self.brand = Brand.find_or_create_by_name(name) if name.present? end and in styles.js.coffeescript: jQuery -> $(''#style_brand_name'').autocomplete source: $(''#style_brand_name'').data(''autocomplete-source'') -- You received this message because you are subscribed to the Goo...
2007 Jan 25
2
text_field_with_auto_complete problem
I have some difficulties with text_field_with_auto_complete. I’m new to this, it just will not work, I must be doing something wrong. It would be great if someone could advise me. I have tried to follow advice available on the internet, so I don’t know what the problem is. The script gets as far as the breakpoint in the controller, but it doesn’t like the next line – giving the error message
2006 Jun 18
5
on change of drop down showing a new textfield
hi, i have a situation where i have a list of options from which a user selects his options if its not in the list he/she selects Others/Not Present and a new textfield should pop up and the data entered there should be considered instead of dropdown. i have done this using javascript/dhtml but i was wondering how this can be done using pure rails i.e using some of the RoR apis?. i would