Topic: how do you make an object?

this sounds reallly stupid...

How do I make an object in erb ?
in controller I just do, @fish = Fish.new
but what of (:fish) ? does fish have to be instanced ? in the controller befor I can use it in the erb ?

Again I am trying the checkbox thing as in my other posts... So I need to send things like

 checkbox(value = (:fish), On/Off ...)

so why check box sends the :fish to the search field that looks in tables :fish :buttons :bottle per whatever checkbox value is sent...

Re: how do you make an object?

You can create the fish in the view just like you do in the controller if you want:

<% @fish = Fish.new %>

Railscasts - Free Ruby on Rails Screencasts

Re: how do you make an object?

Is there any reason you're not doing this in the controller instead?

vinnie - rails forum admin

Re: how do you make an object?

vin wrote:

Is there any reason you're not doing this in the controller instead?

I just don't compleatly get it all just yet on why I can;t just say search this :fish and :buttons and so on...
Hell I don't know why no one has bothered to add in a small How To in the wiki to do a Filtered search But.... I guess I will be the first when ever I get this tongue

Re: how do you make an object?

Ok so is this correct ?>

html
<%= check_box"#{@fish}", "validated" # post.validated? returns 1 or 0 %>

controller

attr_reader :fish, :buttons, :price
def index
  list
  render :action => 'list'
 
end

def initialize
  @fish = fish
  @buttons = buttons
  @price = price
end


From there how can I I don't know send the check box value to the screen somewhere... to turn on or off a word

Last edited by tripdragon (2006-08-15 15:50:10)

Re: how do you make an object?

Controller
def coco
  puts("cocoa leafs")
end

view
<% gbox = DiaryController.new %>
<%= gbox.coco %>


With that I get nothing on screen

Re: how do you make an object?

tripdragon wrote:

Controller
def coco
  puts("cocoa leafs")
end

view
<% gbox = DiaryController.new %>
<%= gbox.coco %>


With that I get nothing on screen

"puts" prints something to the current output. It's not really an efficient way to debug with Rails. Just have the coco method return the string:

# controller
def coco
  "cocoa leafs"
end

# view
<% gbox = DiaryController.new %>
<%= gbox.coco %>


Also, you shouldn't be creating a controller like that. I'd suggest running though some Ruby and Rails tutorials and books because this is fairly basic.

Railscasts - Free Ruby on Rails Screencasts