Hi, I recently started working with rails and maybe Im a bit spoiled coming from a Java background but is there a proper api document for the objects that are used in erb.html pages? For example, I read a tutorial mentioning a form variable that just seem to magically exist (no idea who/where it is actually instantiated, e.g. <%= form.label :name, "Name:" %>) but what methods are available in this form object? And what other objects, and methods, are magically available on erb.html pages? I checked out http://api.rubyonrails.org and it does list a whole bunch of classes and methods but I have no idea what type this "form" variable is referencing. -- Posted via http://www.ruby-forum.com/.
On Tue, Jul 14, 2009 at 1:50 AM, Shahin Kordasti < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I recently started working with rails and maybe Im a bit spoiled coming > from a Java background but is there a proper api document for the > objects that are used in erb.html pages? > > For example, I read a tutorial mentioning a form variable that just seem > to magically exist (no idea who/where it is actually instantiated, e.g. > <%= form.label :name, "Name:" %>) but what methods are available in this > form object? > > And what other objects, and methods, are magically available on erb.html > pages? > > I checked out http://api.rubyonrails.org and it does list a whole bunch > of classes and methods but I have no idea what type this "form" variable > is referencing.Shahin. learning anything takes time. For example. the form in <%= form.label :name, "Name:" %> is called block parameter as in the following: <% form_for :person, :url => { :action => "update" } do |form| %> <%= f.error_messages %> First name: <%= form.text_field :first_name %><br /> Last name : <%= form.text_field :last_name %><br /> Biography : <%= form.text_area :biography %><br /> Admin? : <%= form.check_box :admin %><br /> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Jul 14, 2009 at 2:00 AM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Jul 14, 2009 at 1:50 AM, Shahin Kordasti < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Hi, >> >> I recently started working with rails and maybe Im a bit spoiled coming >> from a Java background but is there a proper api document for the >> objects that are used in erb.html pages? >> >> For example, I read a tutorial mentioning a form variable that just seem >> to magically exist (no idea who/where it is actually instantiated, e.g. >> <%= form.label :name, "Name:" %>) but what methods are available in this >> form object? >> >> And what other objects, and methods, are magically available on erb.html >> pages? >> >> I checked out http://api.rubyonrails.org and it does list a whole bunch >> of classes and methods but I have no idea what type this "form" variable >> is referencing. > > > Shahin. learning anything takes time. For example. the form in > > <%= form.label :name, "Name:" %> > > is called block parameter as in the following: > > <% form_for :person, :url => { :action => "update" } do |form| %> > <%= f.error_messages %> > First name: <%= form.text_field :first_name %><br /> > Last name : <%= form.text_field :last_name %><br /> > Biography : <%= form.text_area :biography %><br /> > Admin? : <%= form.check_box :admin %><br /> > <% end %> > >Also, I would recommend getting a copy of "Agile Web Development with Rails 3rd edition" by Dave Thomas et al. Furthermore, I would take some time learning about the Rails API. Good luck, -Conrad --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Conrad Taylor wrote:> On Tue, Jul 14, 2009 at 2:00 AM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >>> For example, I read a tutorial mentioning a form variable that just seem >> >> Last name : <%= form.text_field :last_name %><br /> >> Biography : <%= form.text_area :biography %><br /> >> Admin? : <%= form.check_box :admin %><br /> >> <% end %> >> >> > Also, I would recommend getting a copy of "Agile Web Development with > Rails > 3rd edition" by Dave Thomas et al. Furthermore, I would take some time > learning about the Rails API. > > Good luck, > > -ConradThanks for the info and I got that book you mentioned. However I wanted an easily available api doc (like Suns javadoc) where I could find this "form" parameter (and others like it) and what fields are available. For example you mention form.text_field, form.text_area. What others are there and are they listed anywhere? -- Posted via http://www.ruby-forum.com/.
The API ref at api.rubyonrails.org is the main source, but reading it sometimes requires a little more understanding. The object passed to form_for''s block is an instance of ActionView::Helpers::FormBuilder. There''s not explicit documentation for it, as most of it''s methods are metaprogrammed versions of the methods in ActionView::Helpers::FormHelper. FormBuilder''s methods are essentially partially applied versions of FormHelper''s, in that they don''t require the first argument. Thus, the middle statement here: <% form_for ''thing'' do |form| %> <%= form.text_field :name %> <% end %> is identical to: <%= text_field ''thing'', :name %> It''s a handy shorthand, and also makes some things (rendering fields in a partial, for instance) much easier. Going forward, there are a couple things that will help you figure out what''s going on: - object.inspect will typically get you a short string representation of an object; some objects may not show all fields here, but at least the type will be visible - object.debug (in a view) will output a YAML version of the given object, wrapped in ''pre'' tags. This can be useful for debugging models, for instance. - if all else fails, install ruby-debug and put ''debugger'' wherever needed. You can even use it inside of ERB views! Hope this helps. --Matt Jones On Jul 14, 5:25 am, Shahin Kordasti <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Thanks for the info and I got that book you mentioned. However I wanted > an easily available api doc (like Suns javadoc) where I could find this > "form" parameter (and others like it) and what fields are available. For > example you mention form.text_field, form.text_area. What others are > there and are they listed anywhere? > -- > Posted viahttp://www.ruby-forum.com/.
Just as a mention, erb is not rails specific. It is something that rails uses heavily in its views templates but it is really ruby specific. The Ruby language created the concept of erb so that html files could house ruby code. If you want to learn more about erb, you need to search the proper api documentation: http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html -- Posted via http://www.ruby-forum.com/.
I''ve been finding it a little annoying as well. I''m learning Rails through "Agile Web Development with Rails 3rd edition" and I''m also picking up Ruby at the same time. This is my first web framework...and for the most part, Agile has been a great source for learning Rails. I''m in Chapter 9, where in the section where it''s going through partial templates. <%= render(:partial => "cart_item" , :collection => @cart.items) %> This is a bit of code from it, where the book uses the method rendor() (I''ve been following along and writing code as I go). My question, here, is where do I find documentation for the method render? I looked it up in the http://api.rubyonrails.org/ api, but when it comes to render, all it says is " render(template, local_assigns) " ... okay, template I can get, but local_assigns? What are they? I search, but can''t find anything within the api about it. Either I''m just too newbie like to get it, or there''s something wrong with the rails documentation. I''d probably be closer to betting on my newbieness :P Thanks guys, On Jul 14, 12:41 pm, "Älphä Blüë" <rails-mailing-l...@andreas-s.net> wrote:> Just as a mention, erb is not rails specific. It is something that > rails uses heavily in its views templates but it is really ruby > specific. > > The Ruby language created the concept of erb so that html files could > house ruby code. If you want to learn more about erb, you need to > search the proper api documentation: > > http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html > > -- > Posted viahttp://www.ruby-forum.com/.
Matt Jones wrote:> The API ref at api.rubyonrails.org is the main source, but reading it > sometimes requires a little more understanding. > > The object passed to form_for''s block is an instance of > ActionView::Helpers::FormBuilder. There''s not explicit documentation > for it, as most of it''s methods are metaprogrammed versions of the > methods in ActionView::Helpers::FormHelper. FormBuilder''s methods are > essentially partially applied versions of FormHelper''s, in that they > don''t require the first argument. Thus, the middle statement here: > > <% form_for ''thing'' do |form| %> > <%= form.text_field :name %> > <% end %> > > is identical to: > > <%= text_field ''thing'', :name %> > > It''s a handy shorthand, and also makes some things (rendering fields > in a partial, for instance) much easier. > > Going forward, there are a couple things that will help you figure out > what''s going on: > > - object.inspect will typically get you a short string representation > of an object; some objects may not show all fields here, but at least > the type will be visible > > - object.debug (in a view) will output a YAML version of the given > object, wrapped in ''pre'' tags. This can be useful for debugging > models, for instance. > > - if all else fails, install ruby-debug and put ''debugger'' wherever > needed. You can even use it inside of ERB views! > > Hope this helps. > > --Matt Jones > > On Jul 14, 5:25�am, Shahin Kordasti <rails-mailing-l...@andreas-s.net>Thanks, that will help alot. However as the poster above mentions there is alot to be desired when it comes to Ruby/Rails documentation. Like the render method, I too am wondering what local_assigns is and how they can be used. From the name I assume it is a way to pass local variables to the page but that is only an assumption on my part. Others issues I have is with the ORM framework and the find method. It can take a whole bunch of options (like :first and so on) but where are all these options listed? -- Posted via http://www.ruby-forum.com/.
Shahin Kordasti wrote: [...]> However as the poster above mentions there is alot to be desired when it > comes to Ruby/Rails documentation.The documentation is actually very good, but you have to understand how it''s organized.> Like the render method, I too am > wondering what local_assigns is and how they can be used. > > From the name I assume it is a way to pass local variables to the page > but that is only an assumption on my part.This is addressed somewhere in the RDoc, probably in ActionController, although I don''t remember offhand. A lot of useful information is in the preamble to each class document, rather than under individual methods. This makes sense when you consider that many of the most commonly used methods in the Rails framework are actually metaprogrammed in or faked with method_missing, so RDoc won''t create entries for them.> > Others issues I have is with the ORM framework and the find method. It > can take a whole bunch of options (like :first and so on) but where are > all these options listed?Right in the ActiveRecord::Base RDoc file. Try reading it sometime. :) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.