ruby on rails - Getting the filename through Carrierwave in model -


i hoping insight on how retrieve file name submitted in order read file temp variable , processing on it.

i have been trying incorporate carrierwave's gem project i'm working on deals parsing in text , formatting it. have code working input copied text field have made can't seem incorporate text submitted file.
relevant portion of model below:

class jdatum < activerecord::base mount_uploader :text, textuploader after_validation  :setoutput    private   def setoutput     if self.jinput.size == 0         dir = self.text.file.filename         contents = dir.to_s.read         parsed = json.parse(contents)         self.joutput = init_parse(parsed)     else parsed = json.parse(self.jinput)          self.joutput = init_parse(parsed)     end end 

i have tried multiple ways posted try , file name after submit result in either saying text nil, or method doesn't exist nil class.

undefined method `filename' nil:nilclass

i pretty followed railscast tutorial submitting , putting pictures difference interested in text files instead.

below view show output joutput still called regardless of type of input shown in model assign joutput either input went text file or uploaded file.

<p>   <center><h1 style = "color:#000">formatted output</h1></center>   <strong style = "color:#333"><%= simple_format(@j_datum.joutput) %></strong> </p>  <%= link_to 'edit', edit_j_datum_path(@j_datum) %> | <%= link_to 'back', j_data_path %> 

and here view input done f.file_field :text upload button on form.

<%= form_for @j_datum |f| %>   <% if @j_datum.errors.any? %>     <div id="error_explanation">       <h2><%= pluralize(@j_datum.errors.count, "error") %> prohibited j_datum being saved:</h2>        <ul>       <% @j_datum.errors.full_messages.each |msg| %>         <li><%= msg %></li>       <% end %>       </ul>     </div>   <% end %>    <center><div class="field">     <%= f.label :jinput %><br>     <%= f.text_area :jinput ,:cols => 100, :rows => 25%>   </div></center>   <p>      <%= f.file_field :text %>   </p>   <center><div class="actions">     <%= f.submit %>   </div></center> <% end %> 

add following form_for :

 :html => { :multipart => true } 

for example:

<%= form_for @j_datum, :html => { :multipart => true } |f| %> 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -