# HTML shortcuts

**URL:** <https://www.ruby-forum.com/t/html-shortcuts/89538>\
**Category:** Rails\
**Created:** [March 21, 2007, 1:20am UTC](https://www.ruby-forum.com/t/html-shortcuts/89538 "2007-03-21T01:20:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckonrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a4c791/32.png) [@ckonrad](https://www.ruby-forum.com/u/ckonrad)\
**Post date:** [March 21, 2007, 1:20am UTC](https://www.ruby-forum.com/t/html-shortcuts/89538/1 "2007-03-21T01:20:51Z")

</div>

I am just learning ruby on rails, i have known HTML for a few years now  
and i dont really see how the HTML control shortcuts in Erb are  
shortcuts they just seem to be a different way of creating an HTML  
control not a shortcut.

I mean look at these two form tags does the first one seem like a  
shortcut? Maybe that is just the opinion of the author of the book i am  
reading i dont know, am i missing something? Thanks

\<%= start\_form\_tag ({:action =\> “at”}, {:method =\> “post”}) %\>  
\<%= end\_form\_tag %\>

\<form action = "/look/at" method = "post"

---

<div class="post-metadata">

**Author:** ![ckonrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a4c791/32.png) [@ckonrad](https://www.ruby-forum.com/u/ckonrad)\
**Post date:** [March 21, 2007, 7:29am UTC](https://www.ruby-forum.com/t/html-shortcuts/89538/2 "2007-03-21T07:29:31Z")

</div>

Corey,

That is the older deprecated way. The new way is:

\<% form\_tag :action =\> ‘create’ do %\>  
…  
\<% end %\>

Hope this helps.

–  
Zack C.  
[http://depixelate.com](http://depixelate.com)

---

<div class="post-metadata">

**Author:** ![ckonrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a4c791/32.png) [@ckonrad](https://www.ruby-forum.com/u/ckonrad)\
**Post date:** [March 21, 2007, 11:48pm UTC](https://www.ruby-forum.com/t/html-shortcuts/89538/3 "2007-03-21T23:48:06Z")

</div>

Zack C. wrote:

> Corey,
> 
> That is the older deprecated way. The new way is:
> 
> \<% form\_tag :action =\> ‘create’ do %\>  
> …  
> \<% end %\>
> 
> Hope this helps.
> 
> –  
> Zack C.  
> [http://depixelate.com](http://depixelate.com)

Ok thanks, i still dont see how that new way is a shortcut though, why  
not just use the normal HTML way? does the form\_tag above do something  
different than the normal HTML tag? It just seems like a way of  
using ruby to create a form instead of HTML what is the practical  
difference?

thanks

---

<div class="post-metadata">

**Author:** ![ckonrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a4c791/32.png) [@ckonrad](https://www.ruby-forum.com/u/ckonrad)\
**Post date:** [December 28, 2009, 4:31pm UTC](https://www.ruby-forum.com/t/html-shortcuts/89538/4 "2009-12-28T16:31:04Z")

</div>

Corey K. wrote:

> Zack C. wrote:
> 
> > Corey,
> > 
> > That is the older deprecated way. The new way is:
> > 
> > \<% form\_tag :action =\> ‘create’ do %\>  
> > …  
> > \<% end %\>
> > 
> > Hope this helps.
> > 
> > –  
> > Zack C.  
> > [http://depixelate.com](http://depixelate.com)
> 
> Ok thanks, i still dont see how that new way is a shortcut though, why  
> not just use the normal HTML way? does the form\_tag above do something  
> different than the normal HTML tag?

Yes. It calculates the URL for the form from the controller and action,  
which is a big help since Rails doesn’t use direct URLs much. In  
addition, if you use form\_for, it also creates a FormBuilder object so  
you can use Rails’ helpers for form elements, which automatically pick  
up values from the object. .

> It just seems like a way of  
> using ruby to create a form instead of HTML

It is.

> what is the practical  
> difference?

The URL calculation is a big difference.

> thanks

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ckonrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a4c791/32.png) [@ckonrad](https://www.ruby-forum.com/u/ckonrad)\
**Post date:** [December 28, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/html-shortcuts/89538/5 "2009-12-28T17:41:27Z")

</div>

On Dec 28, 4:31 pm, Marnen Laibow-Koser [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yes. It calculates the URL for the form from the controller and action,  
> which is a big help since Rails doesn’t use direct URLs much. In  
> addition, if you use form\_for, it also creates a FormBuilder object so  
> you can use Rails’ helpers for form elements, which automatically pick  
> up values from the object. .

And with form\_for rails works out for you whether the form’s action  
should be the url for saving or updating the form etc.

It’s true that

\<%= start\_form\_tag ({:action =\> “at”}, {:method =\> “post”}) %\>  
\<%= end\_form\_tag %\>

is not very different from

\<form action = "/look/at" method = "post"

but

\<% form\_for @person do |f| %\>  
\<%= f.label :name %\>: \<%= f.text\_field :name%\>  
\<% end %\>

is less cumbersome than the alternative.

Fred

–

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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![ckonrad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a4c791/32.png) [@ckonrad](https://www.ruby-forum.com/u/ckonrad)\
**Post date:** [December 28, 2009, 9:43am UTC](https://www.ruby-forum.com/t/html-shortcuts/89538/6 "2009-12-28T09:43:21Z")

</div>

Corey K. wrote:

> Zack C. wrote:
> 
> > Corey,
> > 
> > That is the older deprecated way. The new way is:
> > 
> > \<% form\_tag :action =\> ‘create’ do %\>  
> > …  
> > \<% end %\>
> > 
> > Hope this helps.
> > 
> > –  
> > Zack C.  
> > [http://depixelate.com](http://depixelate.com)
> 
> Ok thanks, i still dont see how that new way is a shortcut though, why  
> not just use the normal HTML way? does the form\_tag above do something  
> different than the normal HTML tag? It just seems like a way of  
> using ruby to create a form instead of HTML what is the practical  
> difference?
> 
> thanks

Dear Zack and Corey,

I am in the same boat as Corey. Don’t see much of a shorcut but  
definitely see a whole lot of confusion. The documentation that i have  
read so far does not seem to be make it better. In fact, I tried running  
this code with Rails on Ruby 1.8.6-p383 and got eyeful of complains from  
the firefox and IE. This after using the old deprecated way and the new  
way. Is there any documentation that explains all this very well?

Appreciate any help here. Thank you

Muru
