search for: find_by_name

Displaying 20 results from an estimated 153 matches for "find_by_name".

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 English name which sucks cause apparently when the user uses German it'...
2008 Jul 21
0
Re: find_by_name won't return record id
...after a couple of months > with RoR. Thanks for all the great information so far. > > I''m using mysql. I have a model called "Role". I''m trying to retrieve > the id for a record that has name = "Admin". From the Ruby console: > > >> Role.find_by_name("Admin") > > => #<Role id: 233, created_at: "2008-07-21 12:55:27", updated_at: > "2008-07-21 12:55:27", name: "Admin">>> Role.find_by_name("Admin").name > => "Admin" > >> Role.find_by_name("Admin...
2006 Jul 02
5
Pretty URLs -> Routes
Hi I am having issues with getting my pretty urls to work. routes.rb: map.connect '':user'' , :controller => ''front'' , :action => ''list'' , :filter => ''user'' front_controller.rb: def list @advert_pages, @adverts = paginate :adverts, :per_page => 10 @user =
2008 Jul 08
3
undefined method `name' ...........
...n browsing my ''story'' (http://localhost:3000/story), I get this error: undefined method `name'' for [#<Story id: 2, name: "sitepoint", link: "http://sitepoint">]:Array Now using the Rails console within Netbeans, gives me this >> v = Story.find_by_name(''sitepoint'') v = Story.find_by_name(''sitepoint'') => #<Story id: 2, name: "sitepoint", link: "http://sitepoint"> >> v.name v.name => "sitepoint" No problem with ''name'' - so what is the difference ?...
2007 Jun 18
2
extending Array class with a method
...i, Let''s say I have an ActiveRecord::Base class and I want to be able to call a method on an Array of these items. For instance, perhaps there''s a class called Country and another called business, and I''d like to be able to do something like great_white_north = Country.find_by_name(''Canada'') canuck_enterprises = great_white_north.businesses countries = Country.find_by_name([''Canada'',''UK'',''Australia'') we_love_the_queen_enterprises = countries.businesses So I need to somehow extend the Array class I thin...
2006 Jul 17
10
getting the user name
Hi I am new to ruby and trying to obtain the user name in the login index.rhtml where I could display "You have logged in [user name]" How could I do this? I have been trying different options after reading the ruby manual but still throw an error. please help -- Posted via http://www.ruby-forum.com/.
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 Page Model def self.find_by_name(pagename) find(:first, :conditions => "name = ''#{pagename}''") end I keep getting an error...
2013 Mar 28
1
undefined method 'sanitize_limit' for #<ActiveRecord::Relation:0x2aaaad35d720>
...rch_column_name => attributes[search_column_name]).first I found following solution on internet: https://github.com/rails/rails/issues/1974 Hence updated to: test = where(search_column_name => attributes[search_column_name]).all.to_a.first ...and this statement started working fine. But, find_by_name() is still failing with the same error. for eg. the below statement is not always working. test_lookup = find_by_identifier(lookup_str) || find_by_name(lookup_str) || find_by_abbreviation(lookup_str) statement is called under a function, defined in a model: def self.lookup(lookup_str) return ni...
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 field set to their i...
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/.
2007 Jun 23
3
has_and_belongs_to_many and dynamic find
...ecord::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 # FOLLOWING DOES NOT WORK # @user.roles << Role.find_by_name( ''registered'' ) # But this this is Fine ! @user.roles << Role.find( :first, :conditions => [''name = ?'', ''registered''] ) When using the usal find( :first) style everythign is sweet, associaiton is built and appears in...
2007 May 22
3
can I use acts_as_list with a has_many :through association
...tActivity < ActiveRecord::Base belongs_to :activity belongs_to :unit acts_as_list :scope => :unit_id end In he example below in script/console I load in some previously created activities; make a new unit; and add the activities to the unit. >> activity_crystals = Activity.find_by_name("Molecular crystals") >> activity_browning = Activity.find_by_name("Brownian motion") >> activity_mixing = Activity.find_by_name("Temperature of mixing >>water - TEEMSS demo") >> my_unit = Unit.create(:name => "My First Unit", :...
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
...he intermediate model is not completely dumb, and my scope trickery doesn''t make it any better. Now, let''s assume for a moment that participants was a plain has_many association. Then it would be possible to write things like m.participants.clear m.participants << Person.find_by_name(''Steve McKing'') m.participant_ids = params[:movie][:participants] With the given has_many :through, none of these work, as Role object won''t validate without a role type. Anyway, what I would like to write is m.participants.as(''actor'').clear m.partic...
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 School? p.school.id == p.school_id # false !!! Of course, p.school(:reload) works fine, but...
2006 Nov 08
3
How to implement status codes in DB and Rails
This is more of a design issue I''m wrestling with, and was wondering what other people are doing. I have a products table with status values of In Stock, Out of Stork or Discontinued. This is unlikely to change any time soon. Approach A, is to have thses actual values in the status column, at least the meaning is very apparent, yet querying for products with a specific status could
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 (&quot...
2009 Oct 08
6
Eager Loading a Relationship That Has No PK/FK
...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 PK/PK relation so the actual Segment class looks like this: class Segment < AR::Base def media @media ||= Media.find_by_name("#{name}%02d" % part) end end This leaves me stuck with a N+1 select problem because I can''t say: Segment.all :include => :media or Show.all :include => {:segment=>:media} How to get around the N+1? select problem and eager load Media? In the case of Show.all, Sh...
2006 Mar 12
3
Newbie: using find like a sql join query
I have a working Rails app with several related tables, but can''t find an answer to this question in the Dave Thomas Rails book. Imagine for example: table departments with columns: id, department_name table employees with columns: id, department_id, employee_name and of course the employees table has a constraint foreign key (department_id) references departments(id) So this is
2006 Feb 13
1
autocomplete input field name
...<input name="bookid" value="<%= @book.id %>" type="hidden"> ... book_controller.rb class BookController < ApplicationController auto_complete_for :author, :name, :limit => 5 def addauthor @book = Book.find(params[:bookid]) @author = Author.find_by_name(params[:authorname]) @book.authors.push(@author) redirect_to :controller => ''book'', :action => ''show'', :id => @book end When I manually enter the right url with variabels (is it english?) bookid and authorname it works, but when I use the form...