Committing files uploaded by the user to GIT?

Hi,
I am trying to commit files uploaded by my user to GIT using ‘grit’ but
can’t figure out how to achieve this.
My file is stored in an ‘upload’ object. I tried ‘upload.commit’ but
this doesn’t work. I’m guessing it’s because the ‘upload’ object is a
hash, which means I was trying to commit the hash.

The model I’m using for this is attached. Any help would be great. Also
if anyone can recommend any GRIT documentation/tutorials that would be
useful, as I can’t find very much info out there.

Thanks,
Jen.

Hi,
I’m a bit closer to achieving what I want, but still could use a few
pointers.

I believe I need to use ‘repo.commit_all’ after the file has been
uploaded. I’ve added a method to my model and am calling it from the
upload controller. I keep getting the following error:

ArgumentError in UploadController#create

wrong number of arguments (0 for 1)

|Rails.root: /home/resource_portal/website|

Application Trace http://localhost:3000/upload# | Framework Trace
http://localhost:3000/upload# | Full Trace
http://localhost:3000/upload#

|app/models/data_file.rb:18:in commit' app/controllers/upload_controller.rb:9:in create’
rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_controller/metal/implicit_render.rb:4:in
send_action' rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:151:in process_action’
|

The model and controller are attached.

Thanks in advance for any help,
Jen.

Jen wrote in post #999450:

ArgumentError in UploadController#create

wrong number of arguments (0 for 1)

Ruby is telling you what the problem. For example, take a look at the
following:


def my_method(arg)
puts “hello world”
end
my_method

Running the above script generates this error:


ArgumentError: wrong number of arguments (0 for 1)

method my_method in demo.rb at line 4
at top level in demo.rb at line 4

If you can figure out why the above fails, then you should be able to
figure out why your application is producing that same error. Also
notice that the error above even tells you which line of code is
producing that error.

|Rails.root: /home/resource_portal/website|

Application Trace http://localhost:3000/upload# | Framework Trace
http://localhost:3000/upload# | Full Trace
http://localhost:3000/upload#

|app/models/data_file.rb:18:in commit' app/controllers/upload_controller.rb:9:in create’

rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_controller/metal/implicit_render.rb:4:in

`send_action’

rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:151:in

`process_action’
|

I’ll leave it as an exercise for you to find the problem from here. It’s
a valuable skill to know how to read error messages, and follow stack
traces from your programing language. It’s something all developers need
to practice. Don’t let errors like this freak you out. If you take the
time to understand them, they often tell you exactly what’s wrong, and
exactly where to look.

Hi list,
Finally got stuff committing to GIT, but not sure what the heck is going
on with the ‘message’ variable, so need to do some reading to refresh my
memory of that. I’ve attached my code in case anyone is interested :stuck_out_tongue:

It’s probably the biggest cludge in the world, so any suggestions on how
I could improve it would be great!

Thanks,
Jen.

Hi,
Thanks for the suggestions. I’ve restructured my application a bit, but
am running in to problems with ‘repo’ not being defined in the
controller. I’m actually a bit confused about where the method to commit
the files should go. My thinking is that it should be in the model (as
that handles validation and persistence) and the controller call it If
this is not the correct way to do things I’d be glad to here any
suggestions.

Also I’m currently creating the ‘repo’ object, then giving it to the
method as an argument. Can I create it inside the method then just call
the ‘.commit_all’ method on it?

Do I even need my own method? Can I just create the repo object in the
model then call repo.commit_all on it?

My revised controller and model are attached.

Thanks,
Jen.