similar to: extending Array class with a method

Displaying 20 results from an estimated 5000 matches similar to: "extending Array class with a method"

2010 Sep 12
11
Rails 3: finding a record by name in multilingual app
Hello, I upgraded my application from Rails 2 to Rails 3 and ran into a problem. In rails 2 I could use the english name of the record to find it like: Page.find_by_name("Welcome") even though the user chose German as the language (which of course showed the German welcome page. Eversince I switched to Rails 3 (default_locale still :en) I can''t find anything by giving the
2008 Jul 08
3
undefined method `name' ...........
Hi Community.... I''m new in this game, so this might be a easy question, but I have done my google, without result, so I will try this.... I''m learning ROR, and I''m using Patrick Lens ''Ruby on Rails'' book. (This is written for ror 1.x - and I''m using NetBeans 6.1 - ror 2.x - this might be the problem...) But... I have made this
2013 Mar 28
1
undefined method 'sanitize_limit' for #<ActiveRecord::Relation:0x2aaaad35d720>
I am trying to upgrate rails from 3.0 to 3.1, while updating rails version I am getting following error rake aborted! undefined method `sanitize_limit'' for #<ActiveRecord::Relation:0x2aaaad35d720> /some_package/lib/ruby/gems/1.8/gems/activerecord-3.1.12/lib/active_record/relation.rb:460:in `method_missing''
2006 Aug 14
4
Controller method problem
Hi, I have a def in my controller see below where i want to find the page object based on a parameter value and then use the page_id to then find all the contents that belong to that page in the same method. Controller def aboutus @page = Page.find_by_name(params[''About Us'']) @contents = Content.find(:all, :conditions => "page_id = #{@page.id}") end
2007 Jun 23
3
has_and_belongs_to_many and dynamic find
Hi Just curious if anyone can explain why using a dynamic find fails to work with << operator I have standard habtm relationship class User < ActiveRecord::Base has_and_belongs_to_many :roles Now when I assign a Role via << after saving the new User I get wierd behaviour but only when using the dynamic version of find i.e @user = User.new(p) if @user.save #
2006 Mar 02
3
Modifying "Find" to always add a condition?
I''d like to always add a condition to any version of "find" (e.g. Thing.find(), Thing.find_by_name(), Thing.find_by_whatever) so that in addition to whatever conditions are set, an additional condition is set :conditions=>"user_id=#{current_user.id}" I''d like to make sure that a user only sees/edits/creates entries in the database that have the user_id
2007 May 22
3
can I use acts_as_list with a has_many :through association
I''d like to be able to use a has_many :through association and treat the associations as a list but I''m getting this error when I try an use an acts_as_list method: NoMethodError: undefined method `move_to_bottom'' I''m using edge rails r6786. Here are my domain rules: Activities are things students can do. Units consists of a sequenced list of
2006 Jul 31
2
Updating a belongs_to foreign key leaves the old association object available
Perhaps this is intentional, but it seems unlikely: class Person < ActiveRecord::Base belongs_to :school end p = Person.find(:first) p.school # nil p.school_id = School.find_by_name(''High School'').id p.school.name # High School p.school_id = School.find_by_name(''Primary School'').id p.school.name # High School <= Shouldn''t this be Primary
2006 Apr 22
3
how do I manually throw a 404?
I''m sure this has been asked before but a quick search on the web didn''t give me any hints.. I''d like to do this: @person = Person.find_by_name throw_page_not_found unless @person Anybody know how to do this, do I have to manually tinker with the response object? -- Posted via http://www.ruby-forum.com/.
2006 May 29
4
Prompting user to enter value to feed Find
Hi, While viewing part of a long list of records, the user may want to do a Find of a specific record (for example, find_by_name). The found record is then displayed using the list view. I''ve searched the wiki and couldn''t find a sample or information that will help directly in implementing this function. Any pointers? Thanks! gk -- Posted via http://www.ruby-forum.com/.
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
I have a model layer containing Movie, Person, Role, and RoleType, making it possible to express facts such as "Clint Easterbunny is director of the movie Gran Milano". The relevant model and associations look like this class Movie < ActiveRecord::Base has_many :roles, :include => :role_type, :dependent => :destroy has_many :participants, :through => :roles, :source
2006 Feb 13
1
autocomplete input field name
Hi All, I''m new to ruby on rails and I struggle with a problem in my first application. I searched the forum (and ofcourse google) but I think it is just an easy thing that nobody boughters to write down :) I am building a kind of library application for (fysical) books and e-books and later I want to add other functions like knowledge management. The problem: in the book show page
2006 Feb 26
1
HABTM SQL generated
I have a HABTM relationship between 2 tables : companies and services. I want to find all the companies who provide a particular service so I''m using @companies = Service.find_by_name(''servicename'').companies. But in the development log, rails appears to be making 2 sql calls - one to find the id of the service and a 2nd to find the companies by that id. How can i
2007 Apr 29
1
better nested set and :through
Hello all, It''s been a while since i''ve been doing any rails development, so i''m a bit rusty. Having found this: http://opensource.symetrie.com/api/better_nested_set/ it looks really interesting and useful for solving something i''m trying to get working. What i have (essentially) is the following models: class Group < ActiveRecord::Base
2009 Oct 08
6
Eager Loading a Relationship That Has No PK/FK
I''m attempting to wrestle an old DB into Rails. This relationship is giving me trouble: class Show < AR::Base has_many :segments end class Segment < AR::Base belongs_to :show has_one :media #this has no PK/FK relation end A Segment is "linked" to Media by Media.name, which is the result of concatenating Segment.name and Segment.part. As I said there are is no
2010 May 12
16
In development mode not all types are included in the query related to type
class User end class Agent < User end script/console production User.find_by_name ''john'' SELECT "people".* FROM "people" WHERE ((("people"."type" = ''User'' OR "people"."type" = ''Manager'') OR "people"."type" = ''Agent'')) AND
2006 Jun 10
3
Weird Problem With Active Record
Is it me or is my model getting the created_at from the wrong model! I have a HABTM relationship between Problems and Tags. In one of my controller I do the following: def view @tag = Tag.find_by_name @params[:id] end In my view I do this: <% @tag.problems.each do |problem| %> ... <%= problem.created_at %> ... <% end %> Now, how come the created_at
2006 Jun 09
2
Creating An Extra Association Between Two Tables
Good Friday Everyone :-). These are my models: Problem -> has_and_belongs_to_many :tags Tag -> has_and_belongs_to_many :problems Now if a tag does not exist and I create it and associate it to the problem it works self.tags << Tag.create(:name => tag) But if I have the tag already in the DB and just want to link it to another problem it does not really like me. I do it
2013 May 28
3
AR's find_by_* limits return results. How to avoid id?
When I use find_by_name method I get LIMIT 1 result. > SELECT "users".* FROM "users" WHERE "users"."age" = 25 LIMIT 1 But the "age" column is not unique in my table and its value may repeat. So I expect that an array of records where "age" is 25 will be returned. But AR limits the query by 1. How to avoid it? Or is it the default
2010 May 08
2
uninitialized constant - Please Help Me...
Hello everyone, I''ve decided to take the step into creating a mini-forum for my website where users can open new posts on exixting topics and allow people to discuss things etc... I am following a tutorial in the book: APRESS - Practical Rails Social Networking Sites and have hit a minor issue. Part of the Forum requirements is to add a moderator role to allow only certain individuals