Reply to topic
Nil Object
rdx73


Joined: 04 Feb 2007
Posts: 15
Reply with quote
Hi Everyone:

Can anyone help me on this. Getting the following error:

Showing app/views/admin/list_custompage.rhtml where line #11 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each

Extracted source (around line #11):

8: </table>
9: <strong>Custom Pages</strong>
10: <table width="100%" border="0" cellspacing="0" cellpadding="0">
11: <%for customhtml in @customhtml%>
12: <tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
13: <td align="left" valign="middle" width="449" >
14: <%=customhtml.name%></td>



Here is the code section in \app\controllers\admin_controller.rb:

def edit_custompage
@customhtml = customhtml.find(params[:id])
end

def update_custompage
@customhtml = customhtml.find(params[:id])
if @customhtml.update_attributes(params[:customhtml])
flash[:notice] = 'Custom page successfully updated.'
render :action => 'edit_custompage', :id => @products
else
render :action => 'edit_custompage'
end
end


def create_custompage
@customhtml = customhtml.new(params[:custom_html])
if @customhtml.save
flash[:notice] = 'Custom page was successfully created.'
redirect_to :action => 'list_custompage'
else
render :action => 'new_custompage'
end

def new_custompage
@customhtml = customhtml.find_all
end

def destroy_custompage
customhtml.find(params[:id]).destroy
redirect_to :action => 'list_custompage'
end


def list_custompage
@customhtml_pages, @customhtml = paginate :customhtml, :per_page => 10
end


Here is the app\views\admin\list_custompage.rhtml:

<div align="left">
<table align="center" width="98%" cellspacing="0" cellpadding="0" ><tr><td colspan="3" valign="TOP"><div align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td ><h2>Custom Page Editor </h2></td>
</tr>
</table>
<strong>Custom Pages</strong>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%for customhtml in @customhtml%>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<td align="left" valign="middle" width="449" >
<%=customhtml.name%></td>
<td align="RIGHT" width="50" ><%= link_to 'Edit', :action => 'edit_custompage', :id => custompage%></td>
<td align="RIGHT" width="51" ><%= link_to 'Delete', { :action => 'destroy_custompage', :id => custompage }, :confirm => "Are you sure?", :post => true %></td>
</tr>
<% end %>
</table>
<%= if @customhtml_pages.current.previous
link_to("Previous page", { :page => @customhtml_pages.current.previous })
end
%> <%= if @categories_pages.current.next
link_to("Next page", { :page => @customhtml_pages.current.next })
end
%><br />
<%= button_to 'Add Custom Page', :action => 'new_custompage' %> </div></td>
</tr>
</table>
</div>
Models are Capital
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 340
Reply with quote
Rob,
in Rails models are capitals, so in order to address your concerns, change customhtml to Customhtml. I did this too when I was first learning rails.
Still Getting Error
rdx73


Joined: 04 Feb 2007
Posts: 15
Reply with quote
Here is the error :

SyntaxError in Admin#list_custompage
Showing app/views/admin/list_custompage.rhtml where line #11 raised:

compile error
./script/../config/../app/views/admin/list_custompage.rhtml:11: dynamic constant assignment
_erbout.concat " "; for Customhtml in @Customhtml; _erbout.concat "\n"
^

Extracted source (around line #11):

8: </table>
9: <strong>Custom Pages</strong>
10: <table width="100%" border="0" cellspacing="0" cellpadding="0">
11: <%for Customhtml in @Customhtml%>
12: <tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
13: <td align="left" valign="middle" width="449" >
14: <%=Customhtml.name%></td>



here is the code for the controller:


def edit_custompage
@Customhtml = Customhtml.find(params[:id])
end

def update_custompage
@Customhtml = Customhtml.find(params[:id])
if @Customhtml.update_attributes(params[:Customhtml])
flash[:notice] = 'Custom page successfully updated.'
render :action => 'edit_custompage', :id => @products
else
render :action => 'edit_custompage'
end
end


def create_custompage
@Customhtml = Customhtml.new(params[:custom_html])
if @Customhtml.save
flash[:notice] = 'Custom page was successfully created.'
redirect_to :action => 'list_custompage'
else
render :action => 'new_custompage'
end

def new_custompage
@Customhtml = Customhtml.find_all
end

def destroy_custompage
Customhtml.find(params[:id]).destroy
redirect_to :action => 'list_custompage'
end


def list_custompage
@Customhtml_pages, @Customhtml = paginate :Customhtml, :per_page => 10
end



here is the list_custompage.rhtml:


<div align="left">
<table align="center" width="98%" cellspacing="0" cellpadding="0" ><tr><td colspan="3" valign="TOP"><div align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td ><h2>Custom Page Editor </h2></td>
</tr>
</table>
<strong>Custom Pages</strong>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%for Customhtml in @Customhtml%>
<tr class="<%= cycle('list-line-odd', 'list-line-even') %>">
<td align="left" valign="middle" width="449" >
<%=Customhtml.name%></td>
<td align="RIGHT" width="50" ><%= link_to 'Edit', :action => 'edit_custompage', :id => custompage%></td>
<td align="RIGHT" width="51" ><%= link_to 'Delete', { :action => 'destroy_custompage', :id => custompage }, :confirm => "Are you sure?", :post => true %></td>
</tr>
<% end %>
</table>
<%= if @Customhtml_pages.current.previous
link_to("Previous page", { :page => @Customhtml_pages.current.previous })
end
%> <%= if @categories_pages.current.next
link_to("Next page", { :page => @Customhtml_pages.current.next })
end
%><br />
<%= button_to 'Add Custom Page', :action => 'new_custompage' %> </div></td>
</tr>
</table>
</div>

Thank you so much for your help.
Capitalization
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 340
Reply with quote
Rob, Rails has weird notation conventions. A variable cannot start with a capital unless it is a class. In order to address your concerns, I would suggest replacing @Customhtml with @customhtml, but retaining Customhtml as the model. Unfortunately, as Paul mentioned, Rails is flexible in terms of conventions, but not this one unless you edit the source.
Nil Object
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic