commenting in new.erb template file

app/views/category/new.erb

In this file , i have two line like this

<!-- <p><label for="book_subject">Subject</label>: -->

<!-- <%= collection_select(:book,:subject_id,@subjects,:id,:name) %></p>
-->

But, if these two lines are present , i get an error saying
"you have an unexpected nil error"

well its strange :))
you are Doing exactly ok for comments as i see http://www.w3schools.com/tags/tag_comment.asp
You should post this with new username

RailsConfusing Radha

that may works…:slight_smile:

please look at this also http://htmlhelp.com/reference/wilbur/misc/comment.html

So find where your Ruby error is -- this certainly has nothing to do
with HTML commenting.

Hi,

I am looking for Matz and Keiju’s book is first published, the first Ruby book.Please mail if any one have,

Cheers,
Sai

Can you post categories controller new action content?

change

<!-- <%= collection_select(:book,:subject_id,@subjects,:id,:name) %></

-->

to <%#= collection_select(:book,:subject_id,@subjects,:id,:name) %>

Ugis Ozols wrote:

Can you post categories controller new action content?

here is this:
though the erb is called as "new.erb". the action in the controller is
named as "create"

def create
      @category = Category.new(params[:category])
      if @category.save
            redirect_to :action => 'list'
      else
        # @subjects = Subject.find(:all)
           render :action => 'new'
      end
   end

here is the full content of category_controller.rb

Just thought of giving a bit moe info:
So, i added these two lines back into new.erb and reproduced this error.

here is the exact error message:

Hint: where on line 14 do you see something that should be an Array?

And where is the value of that Array object being set in your code?

Regardless of the HTML comments in your view file, the Ruby inside the
<% %> tags will get evaluated - if it's invalid it will error (as it
is); if it's valid, you'd end up with a commented-out html select
tag...

if you just want it commented, comment the Ruby:

<!-- <%#= collection_select(:book,:subject_id,@subjects,:id,:name) %></p>
-->

If you want a select tag, read the documents on collection_select and
ensure @subjects is correctly populated with objects (or is an empty
array).
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M002303

I am new in ruby but i will try to help you.
I think that in your controller should have the new def
def new
    .......
    @subjects = Subject.find(:all)
   ........
end

this will give information that you need in your view file.

hi,
you can not just comment these lines because the second line having
Ruby code inside<%= ...%>
for this line you may use # like as written below.
<%#= collection_select(:book,:subject_id,@subjects,:id,:name) %>
Now it is commented out. And code will not read this line...

Anything else, You are most welcome.

Santosh

app/views/category/new.erb

In this file , i have two line like this

<!-- <p><label for="book_subject">Subject</label>: -->

<!-- <%= collection_select(:book,:subject_id,@subjects,:id,:name) %></p>
-->

But, if these two lines are present , i get an error saying
"you have an unexpected nil error"

----------------------------
here is the full file:
app/views/category# more new*
<h1>Add new Category </h1>
<%= form_tag :action => 'create'%>
<p><label for="category_title">Category Title</label>:
<%= text_field 'category', 'category_title' %></p>

<p><label for="categoy_short_desc">Category Short Description</label>:
<%= text_field 'category', 'category_short_desc' %></p>

<p><label for="categoy_long_desc">Category Long Description</label>:
<%= text_area 'category', 'category_long_desc' %></p>

<!-- <p><label for="book_subject">Subject</label>: -->

<!-- <%= collection_select(:book,:subject_id,@subjects,:id,:name) %></p>
-->

<%= submit_tag "Create" %>
<%= form_tag %>
<%= link_to 'Back', {:action => 'list'} %>

-----------------------

If i remove these two lines
<!-- <p><label for="book_subject">Subject</label>: -->

<!-- <%= collection_select(:book,:subject_id,@subjects,:id,:name) %></p>
-->

then new.erb works fine.

Why so?
Why can't comment these two lines?

I'm sure there is some problem. But, i couldn't see what it is.

please let me know if u could what the problem is in cmmenting these two
lines.

thanks,
radha
--
Posted viahttp://www.ruby-forum.com/.