Pass the current controller to the model

In the end under the model I need to beable to do this
dirname = “/public/shows/#{controller.controller_name}/”

Thats it really. I am hacking a swfupload script and need to be able to
break it into lots of controllers so duplicating files is just insane if
I can not get this to work

I have no idea what you’re saying… but if you need to pass things to
the
model, make an attribute accessor in the model.

class MyModel < ActiveRecord::Base

attr_accessor :some_var

end

Then you can do

my_model = MyModel.new
my_model.some_var = “test”

my_model.some_var
(should return “test”

That’s how I pass lots of things to my models. Either that, or make a
whole
method in the model that does what you want and have it take parameters.

i will try this thank you.

What I am trying to do to change the string block in my Model to swap
out the code for the controller that is accessing it> Example code
#model
def dirname
dirname = “/public/shows/#{controller.controller_name}/”
end

I need it to turn into this
#model
def dirname
dirname = “/public/shows/caves/”
end

I cant get it to see the controller so far. The controller is simply
def upload
@box = Box.new
end

Infact it does not need the object creation. @box = Box.new
Just the view. Everything seems to happen in the øne attachment model
and the huge lib file I am trying to hack out the need for the model.

Ok I tried it. I am getting

Ok I tried it, but it it just puts the file one directory above

#model

class Attachment < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
attr_accessor :seemee
#def self.get_upload_dir(controller)

upload_dir = “public/attachments/#{controller}/”

#end

def dirname
@seee = seemee

##### This is working without the name.... weird....

dirname = “public/attachments/#{self.controller}/”

dirname = "public/attachments/#{@seee}/"

end

end

#Controller
def new
@fish = Fish.new
@box = Attachment.new
@box.seemee = “public/attachments/fish/”

@fish.seemee = “public/attachments/fish/”

#@fish.get_upload_dir(controller)
end

Brian H. wrote:

You might actually want to look at the attachment_fu or file_column
plugins. They do what you want to do.

Ah but mine is a Flash swfupload tool
http://swfupload.mammon.se/
it is the only one I can find that has a working progress bar
http://developer.assaydepot.com/?p=6

But my issue is that I have a lot of separate shows that have to keep
there files separate from the other shows.

You might actually want to look at the attachment_fu or file_column
plugins. They do what you want to do.

I understand that… what I meant is look at their source code and see
how
they handle this. file_column has /public/model_name as the default file
location, and the model handles the actual receiving and writing of the
file to the right location. Check it out.

Brian H. wrote:

I understand that… what I meant is look at their source code and see
how
they handle this. file_column has /public/model_name as the default file
location, and the model handles the actual receiving and writing of the
file to the right location. Check it out.

Okay so I did do as you said, it seems to just be
File.join(model, attr) the controller has nothing to do with it at all.

As for the controller. I have tried more things

#controller
def new
@fish = Fish.new
@box = Attachment.new
@box.seemee = “public/attachments/fish/”
end

#model
def dirname
@seee = self.seemee
dirname = “public/attachments/#{@seee}/”
end

But no matter what I do it acts like by the time it creates the model
for operation it is to late to send the next line @box.seemee =
“public/attachments/fish/”
It’s like it HAS to reload the model or stall or insert the data before
making the model, or during.
The before_filter does not do the trick though… BAH headaches!

Trip Dragon wrote:

But no matter what I do it acts like by the time it creates the model
for operation it is to late to send the next line @box.seemee =
“public/attachments/fish/”
It’s like it HAS to reload the model or stall or insert the data before
making the model, or during.
The before_filter does not do the trick though… BAH headaches!

So far no luck still. Now I am trying the Mongrel tool again , but might
anyone have any other clues ?