get DB data to rhtml file

<h1>Mystuff#index</h1>
<p><%mystuff.each do |mr|%></p>
<h1>mr.m1</h1>
<% end %>

if you want to display the result of a ruby expression (eg one of your
attributes) then you need to use <%= ... %> (don't forget to use h to
escape nasties (if appropriate))

Fred

Mark Preston wrote:

Frederick Cheung wrote:

<h1>Mystuff#index</h1>
<p><%mystuff.each do |mr|%></p>
<h1>mr.m1</h1>
<% end %>

if you want to display the result of a ruby expression (eg one of your
attributes) then you need to use <%= ... %> (don't forget to use h to
escape nasties (if appropriate))

Fred

When I run the webrick server I get the following error message:

Showing app/views/mystuff/index.html.erb where line #2 raised:

undefined local variable or method `mystuff' for #<ActionView::Base:0x388b348>

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%mystuff.each do |mr|%></p>
3: <h1>=mr.m1</h1>
4: <% end %>

HELP :slight_smile:

Ok, in the controller you are assigning @me to your find. Try:

<% @my.each do |mr| %>

in your view instead.

Also, don't forget to enclose that attribute in tags:

<h1><%= mr.m1 %></h1>

HTH

Matt

Matt Harrison wrote:

Mark Preston wrote:

escape nasties (if appropriate))

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%mystuff.each do |mr|%></p>
3: <h1>=mr.m1</h1>
4: <% end %>

HELP :slight_smile:

Ok, in the controller you are assigning @me to your find. Try:

<% @my.each do |mr| %>

in your view instead.

Also, don't forget to enclose that attribute in tags:

<h1><%= mr.m1 %></h1>

HTH

Matt

Thanks for the reply!

I modified the controller to look like this:

require 'Mystuff'

class MystuffController < ApplicationController

    def read

       @my = Mystuff.find( :all)

    end
  end

and the view to look like this:

<h1>Mystuff#index</h1>
<p><%me.each do |mr|%></p>
<h1><=%mr.m1%></h1>
<% end %>

and am getting the following error:

undefined local variable or method `me' for
#<ActionView::Base:0x381bb24>

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%me.each do |mr|%></p>
3: <h1><=%mr.m1%></h1>
4: <% end %>

Thanks for the continued help !!!!

   @my =  Mystuff\.find\( :all\)

This

<h1>Mystuff#index</h1>
<p><%me.each do |mr|%></p>

and this need to match - the instance variables are copied over for
you.

Fred

Mark Preston wrote:

Matt Harrison wrote:

Mark Preston wrote:

escape nasties (if appropriate))

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%mystuff.each do |mr|%></p>
3: <h1>=mr.m1</h1>
4: <% end %>

HELP :slight_smile:

Ok, in the controller you are assigning @me to your find. Try:

<% @my.each do |mr| %>

in your view instead.

Also, don't forget to enclose that attribute in tags:

<h1><%= mr.m1 %></h1>

HTH

Matt

Thanks for the reply!

I modified the controller to look like this:

require 'Mystuff'

class MystuffController < ApplicationController

    def read

       @my = Mystuff.find( :all)

    end
  end

and the view to look like this:

<h1>Mystuff#index</h1>
<p><%me.each do |mr|%></p>
<h1><=%mr.m1%></h1>
<% end %>

and am getting the following error:

undefined local variable or method `me' for
#<ActionView::Base:0x381bb24>

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%me.each do |mr|%></p>
3: <h1><=%mr.m1%></h1>
4: <% end %>

Thanks for the continued help !!!!

ok, cleaned up some of my silly errors view looks like this now:

<h1>Mystuff#index</h1>
<p><%my.each do |mr|%></p>
<h1><%=mr.m1%></h1>
<% end %>

but still getting the error:

undefined local variable or method `my' for
#<ActionView::Base:0x381bb24>

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%my.each do |mr|%></p>
3: <h1><%=mr.m1%></h1>
4: <% end %>

Frederick Cheung wrote:

� � � �@my = �Mystuff.find( :all)

This

<h1>Mystuff#index</h1>
<p><%me.each do |mr|%></p>

and this need to match - the instance variables are copied over for
you.

Fred

Fred thanks, I saw that and changed it, but still am getting the error:

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

Extracted source (around line #2):

1: <h1>Mystuff#index</h1>
2: <p><%@my.each do |mr|%></p>
3: <h1><%=mr.m1%></h1>
4: <% end %>

and I checked the DB, there is definately data in m1

DB

I got it to work by changing my method in the mystuff_controller to look
like this:

require 'Mystuff'

class MystuffController < ApplicationController

def index

   @my =  Mystuff\.find\( :all\)

end

end

The only change was to change the name of the method to "index" Seems
odd

Seems like you were hitting the index action (ie going to /mystuff )
so your read method was never getting called.

Fred