Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert download a file when creating ...

Replytotopic

download a file when creating a record

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 17
Sign in to rate this post

how can i use send_file helper in create method to saving record?

 
Me

Authority 62
Posting Rating 100
Sign in to rate this post

By using it! ;-) Sorry, but where is the problem?

 
257897794_e8d4f5daf2

Authority 37
Posting Rating 78
Sign in to rate this post

Just to clarify Abolfazi. Are you trying to send a file back to the user after a record is created? Or are you trying to save a file to the server after a record is created?

 
Profile

Authority 12
Posting Rating 76
Sign in to rate this post

you might want to send the file when you have created a record! for this after_create, after_save may be the relative things you want to use, but they are available in the model and you cant call the send_file from the model.

So the easiest solution for this is:

In some controller when you are creating the record

@file = File.create( some parameters for the file )
send_file “path_to_file/file.extention” if @file ( you can also use it like send_file “path_to_file/file.extention” return false if @file if nothing to do after the sending file )

if you have a sequence of steps to some where you can use a variable instead of @file which should decide either to send the file or not!

Thanks
Shafiq

Replytotopic

Other Recent Topics

Ask a Rails expert : Routing problem using patterns for id

Ask a Rails expert : How to work with ror 2.1.1 using Netbeans IDE 6.1

Ask a Rails expert : json gem error

Ask a Rails expert : Problem with break

Ask a Rails expert : activesupport string first method error

Ask a Rails expert : url_for broken ?

Ask a Rails expert : map.routes.rb pls help

Ask a Rails expert : how to h tag in controller

Ask a Rails expert : Problem with Restful routing and partial form

Ask a Rails expert : will_paginate, search and ajax

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel