# How to do a block from embedded ruby (rhtml)

**URL:** <https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909>\
**Category:** Rails\
**Created:** [January 23, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909 "2008-01-23T12:11:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 23, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909/1 "2008-01-23T12:11:49Z")

</div>

I want to drop deprecated code as per:

start\_form\_tag and end\_form\_tag  
Use form\_tag with a block.

> **[Ruby on Rails](https://rubyonrails.org)**
>
> A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

However, I’m not sure how to do a block from the rhtml file. Somewhere  
I  
need curly braces for a block? Or, does it mean an “end” statement?  
The  
embedded part is throwing me off a bit.

thufir@arrakis ~/strawr $  
thufir@arrakis ~/strawr $ cat app/views/feeds/show.rhtml -n | head -n  
53  
| tail -n 18  
36  
37 \<% @unused\_tags =  
38 Tag.find(:all) - @feed.tags %\>  
39  
40 \<% if @unused\_tags.any? %\>  
41  
42 \<%= form\_tag :action =\> “add\_some\_tags”,  
43 :id =\> @feed %\>  
44 **Add a tag:**  
  
45 \<% @unused\_tags.each {|tag| %\>  
46 \<%= check\_box(‘tag’+tag.id.to\_s, ‘checked’) +  
47 tag.tag %\>  
  
48 \<% } %\>  
49 \<%= submit\_tag %\>  
50 \<%= end\_form\_tag %\>  
51 \<% end %\>

52  
53  
thufir@arrakis ~/strawr $

[http://code.google.com/p/strawr/source](http://code.google.com/p/strawr/source)

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 23, 2008, 12:38pm UTC](https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909/2 "2008-01-23T12:38:18Z")

</div>

On 23 Jan 2008, at 11:10, Thufir wrote:

> statement? The  
> embedded part is throwing me off a bit.

\<% form\_tag :action =\> ‘foo’ do %\>  
bla bla bla  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 24, 2008, 10:02am UTC](https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909/3 "2008-01-24T10:02:38Z")

</div>

On Wed, 23 Jan 2008 11:37:17 +0000, Frederick C. wrote:

> \<% form\_tag :action =\> ‘foo’ do %\>  
> bla bla bla  
> \<% end %\>

Following this (and trying to follow the API) results in:

SyntaxError in Feeds#show

Showing app/views/feeds/show.rhtml where line #43 raised:

compile error  
/home/thufir/strawr/app/views/feeds/show.rhtml:43: syntax error,  
unexpected ‘)’  
\_erbout.concat " "; \_erbout.concat(( form\_tag :action =\>  
“add\_some\_tags”, :id =\> @feed.id do ).to\_s); \_erbout.concat “\n”

^  
/home/thufir/strawr/app/views/feeds/show.rhtml:50: syntax error,  
unexpected kEND, expecting ‘)’  
end ; \_erbout.concat “

\n”  
^  
/home/thufir/strawr/app/views/feeds/show.rhtml:57: syntax error,  
unexpected kEND, expecting ‘)’

Extracted source (around line #43):

40: Tag.find(:all) - @feed.tags %\>  
41:  
42: \<% if @unused\_tags.any? %\>  
43: \<%= form\_tag :action =\> “add\_some\_tags”, :id =\> @feed.id do %\>  
44: **Add a tag:**  
  
45: \<% @unused\_tags.each {|tag| %\>  
46: \<%= check\_box(‘tag’+tag.id.to\_s, ‘checked’) + tag.tag %\>

If line 44 is syntactically correct (which I think it is, then perhaps  
the source of the error message lies in line 46, converting  
tag.id.to\_s ,or maybe there’s a missing “end” (but that part looked ok  
to  
me).

for source code:

[http://code.google.com/p/strawr/source](http://code.google.com/p/strawr/source)  
and  
[http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml](http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml)

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 24, 2008, 11:19am UTC](https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909/4 "2008-01-24T11:19:07Z")

</div>

On 24 Jan 2008, at 09:01, Thufir wrote:

> On Wed, 23 Jan 2008 11:37:17 +0000, Frederick C. wrote:
> 
> > \<% form\_tag :action =\> ‘foo’ do %\>  
> > bla bla bla  
> > \<% end %\>
> 
> Following this (and trying to follow the API) results in:

Well you haven’t done that. you’ve used \<%=, whereas I used \<%

Fred

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 24, 2008, 4:00pm UTC](https://www.ruby-forum.com/t/how-to-do-a-block-from-embedded-ruby-rhtml/126909/5 "2008-01-24T16:00:30Z")

</div>

I stand corrected!

Thanks 🙂

-Thufir
