Hi all, I''ve a entry model and I''ve a entry_type model. How do I to add a select to my view to edit the entry type and focus the current type. Regards, -- TSU. Amador Cuenca -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I tried to do it by myself, I''ve a model named Entry with a field named type_id (added via migration) and a model named EntryType with a field named description. class Entry < ActiveRecord::Base belongs_to :entry_type ... end> class EntryType < ActiveRecord::Basehas_many :entries end I added the following code line to my /_form.erb: <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| [t.description,> t.id]}, {:include_blanks => ''None''}) %>but when I try to load the page I get this exception: NoMethodError in Entries#new Showing *I:/Labs/RailsProjects/sisingresos/app/views/entries/_form.html.erb* where line *#18* raised: undefined method `merge'' for [["Ordinario", 1], ["Especial", 2], ["Concejo Comunal", 3]]:Array Extracted source (around line *#18*): 15: </div> 16: <div class="field"> 17: <%= f.label t(''entries.fields.type'') %><br /> 18: <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| [t.description, t.id]}, {:include_blanks => ''None''}) %> 19: </div> 20: <div class="field"> 21: <%= f.label t(''entries.fields.generalentrydate'') %><br /> Trace of template inclusion: app/views/entries/new.html.erb Rails.root: I:/Labs/RailsProjects/sisingresos Application Trace <http://localhost:3000/entries/new#> | Framework Trace<http://localhost:3000/entries/new#> | Full Trace <http://localhost:3000/entries/new#> app/views/entries/_form.html.erb:18:in `block in _app_views_entries__form_html_erb__326164559_25362852_503356076'' app/views/entries/_form.html.erb:1:in `_app_views_entries__form_html_erb__326164559_25362852_503356076'' app/views/entries/new.html.erb:3:in `_app_views_entries_new_html_erb___750658673_25375572__1012098428'' app/controllers/entries_controller.rb:23:in `new'' Regards, -- TSU. Amador Cuenca -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Donald R. Ziesig
2011-Feb-01 20:46 UTC
Re: [ruby_on_rails] Re: Newbie question: Select with Model
I don''t know if this is the problem, but RAILS_ENV has been deprecated in favor of Rails.env On 2/1/2011 3:20 PM, Amador Antonio Cuenca wrote:> I tried to do it by myself, > > I''ve a model named Entry with a field named type_id (added via > migration) and a model named EntryType with a field named description. > > class Entry < ActiveRecord::Base > > belongs_to :entry_type > > ... > > end > > class EntryType < ActiveRecord::Base > > has_many :entries > > end > > > I added the following code line to my /_form.erb: > > <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| > [t.description, t.id <http://t.id>]}, {:include_blanks => ''None''}) %> > > > but when I try to load the page I get this exception: > > > NoMethodError in Entries#new > > Showing > /I:/Labs/RailsProjects/sisingresos/app/views/entries/_form.html.erb/ where > line *#18* raised: > > |undefined method `merge'' for [["Ordinario", 1], ["Especial", 2], ["Concejo Comunal", 3]]:Array| > > Extracted source (around line *#18*): > > |15:</div> > 16:<div class="field"> > 17:<%= f.label t(''entries.fields.type'') %><br /> > 18:<%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| [t.description,t.id <http://t.id>]}, {:include_blanks => ''None''}) %> > 19:</div> > 20:<div class="field"> > 21:<%= f.label t(''entries.fields.generalentrydate'') %><br /> > | > > Trace of template inclusion: app/views/entries/new.html.erb > > |Rails.root: I:/Labs/RailsProjects/sisingresos| > > Application Trace <http://localhost:3000/entries/new#> | Framework > Trace <http://localhost:3000/entries/new#> | Full Trace > <http://localhost:3000/entries/new#> > |app/views/entries/_form.html.erb:18:in `block in _app_views_entries__form_html_erb__326164559_25362852_503356076'' > app/views/entries/_form.html.erb:1:in `_app_views_entries__form_html_erb__326164559_25362852_503356076'' > app/views/entries/new.html.erb:3:in `_app_views_entries_new_html_erb___750658673_25375572__1012098428'' > app/controllers/entries_controller.rb:23:in `new''| > > Regards, > -- > TSU. Amador Cuenca > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey there Amador, I must confess, I am not a rails guru here but, according to the documentation I have, the part that reads <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| [t.description, t.id]}, {:include_blanks => ''None''}) %> should end with a *{ :include_blanks => false } *not with a *''None''* string value. The other thing here is, if an annotation of your models look something like this: # Table name: entities # # id :integer not null, primary key # type_id :integer . . . # created_at :datetime # updated_at :datetime # Table name: entity_types # # id :integer not null, primary key # type :string(255) . . . # created_at :datetime # updated_at :datetime Then in my understanding rails make the relationship between the two models if you have a field name containing the name of the table you want link to followed by an underscore and the name of the primary key of the referred table: *i.e. enty model needs an entity_type_id field not type_id. * Well I guess that all I can see from what you have provided but like I said I am not an expert and I stand to be corrected. Hope this helps Regards, Tsega -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Amador Antonio Cuenca
2011-Feb-02 19:40 UTC
Re: [ruby_on_rails] Re: Newbie question: Select with Model
*Solved,* I do this: <%= select(:entry, :type_id, EntryType.find(:all).collect {|t| [t.description, t.id]}, {:include_blanks => true}) %> if I put: f.select, It throws a exception... Regards, -- TSU. Amador Cuenca -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 February 2011 20:20, Amador Antonio Cuenca <sphi02ac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I tried to do it by myself, > I''ve a model named Entry with a field named type_id (added via migration) > and a model named EntryType with a field named description. >> >> class Entry < ActiveRecord::Base >> >> belongs_to :entry_typeThe id field for this should be entry_type_id not type_id Colin>> >> ... >> >> end > > >> >> class EntryType < ActiveRecord::Base >> >> has_many :entries >> >> end > > I added the following code line to my /_form.erb: >> >> <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| >> [t.description, t.id]}, {:include_blanks => ''None''}) %> > > but when I try to load the page I get this exception: > > NoMethodError in Entries#new > > Showing I:/Labs/RailsProjects/sisingresos/app/views/entries/_form.html.erb where > line #18 raised: > > undefined method `merge'' for [["Ordinario", 1], ["Especial", 2], ["Concejo > Comunal", 3]]:Array > > Extracted source (around line #18): > > 15: </div> > 16: <div class="field"> > 17: <%= f.label t(''entries.fields.type'') %><br /> > 18: <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| > [t.description, t.id]}, {:include_blanks => ''None''}) %> > 19: </div> > 20: <div class="field"> > 21: <%= f.label t(''entries.fields.generalentrydate'') %><br /> > > Trace of template inclusion: app/views/entries/new.html.erb > > Rails.root: I:/Labs/RailsProjects/sisingresos > > Application Trace | Framework Trace | Full Trace > > app/views/entries/_form.html.erb:18:in `block in > _app_views_entries__form_html_erb__326164559_25362852_503356076'' > app/views/entries/_form.html.erb:1:in > `_app_views_entries__form_html_erb__326164559_25362852_503356076'' > app/views/entries/new.html.erb:3:in > `_app_views_entries_new_html_erb___750658673_25375572__1012098428'' > app/controllers/entries_controller.rb:23:in `new'' > > Regards, > -- > TSU. Amador Cuenca > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 February 2011 20:50, Tsega <tsegaselassi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey there Amador, > > I must confess, I am not a rails guru here but, according to the > documentation I have, the part that reads > > <%= f.select(''entry'', ''type_id'', EntryType.all.collect {|t| [t.description, > t.id]}, {:include_blanks => ''None''}) %> > > should end with a { :include_blanks => false } not with a ''None'' string > value. > > The other thing here is, if an annotation of your models look something like > this: > > > # Table name: entities > # > # id :integer not null, primary key > # type_id :integer > . > . > . > # created_at :datetime > # updated_at :datetime > > # Table name: entity_types > # > # id :integer not null, primary key > # type :string(255)Don''t use a field called type unless you are using STI. ''type'' is a reserved word in Rails. Colin> . > . > . > # created_at :datetime > # updated_at :datetime > > Then in my understanding rails make the relationship between the two models > if you have a field name containing the name of the table you want link to > followed by an underscore and the name of the primary key of the referred > table: i.e. enty model needs an entity_type_id field not type_id. > > Well I guess that all I can see from what you have provided but like I said > I am not an expert and I stand to be corrected. Hope this helps > > > Regards, > Tsega > > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.