Rectangle 27 5

You could have used the *_identifier method, in your case:

comment.file_identifier

ruby on rails - Is there a better way to display the filename in carri...

ruby-on-rails ruby ruby-on-rails-3 carrierwave
Rectangle 27 0

Cropping images with carrierwave in js window.opener [Ruby-on-Rails ...

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# carrierwave use rmagick
gem 'rmagick'
gem 'carrierwave'
gem 'jcrop-rails-v2'
Ruby-on-Rails carrierwave jcrop
Rectangle 27 0

The Carrierwave docs might be a bit off, but recommended way seems to be:

@page.form.file.identifier

works for me on saved records - just as I needed :) thanks!

@page.form.file_identifier

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

If you're using ActiveRecord, you can directly access the field named form in two ways:

def my_method
  self[:form]
end
def my_method
  form_before_type_cast
end

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

@page.form.file.identifier

But when I use that, I always get nil (just as @Cheng commented).

I then inspected my objects methods (@page.form.file.methods.inspect), and found the following to work:

@page.form.file_identifier

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

CarrierWave::SanitizedFile
original_filename
class Upload < ActiveRecord::Base
  mount_uploader :file, FileUploader
  # ...

I heavily modify the :file column value from the original filename. Due to this I decided to track the original filename in a separate column from the one bound to CarrierWave. In my FileUploader I simply added a reader that wraps the private original_filename method:

def original_file
  original_filename
end
Upload
before_create
before_create do
  self.original_file = self.file.original_file
end

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

This is, unfortunately, a thing that happens. Thankfully there is a fix.

Fog::Storage.new(fog_credentials).sync_clock

You should be able to use the same values that you are passing to config in your initializer for fog_credentials here. sync_clock makes a simple request to S3 and stores the offset (and then modifies timestamps it sends by the offset). So that should ensure you won't see this error any more (though it shouldn't come up that often, ie if you redeploy to heroku, the new dynos probably would not have the skew still). Hope that clears it up, but happy to help more if needed.

thanks for your replay its help us in feature for sure because we migrate our app to carrierwave-aws

how to apply sync_clock option on S3 upload with CarrierWave in Ruby O...

ruby-on-rails ruby-on-rails-3 amazon-s3 carrierwave fog
Rectangle 27 0

I'm assuming you've got models like this?

class Page
  mount_uploader :form, FormUploader
end
@page.form.url
@page.form.filename

Are you sure you've uploaded/attached the file correctly? What do you see when you inspect @page.form? Remember, the attachment will not be saved until you've fully processed the upload.

The attachment is saving fine. I've updated my question with the model and uploader code. Don't worry, zanker's answer fixed it.

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

My recommendation is to not add the border/dropshadow in the image (since you may want to display them differently later on), but instead add them using CSS.

for example, you can add a 5 px white padding around the image, and then a box-shadow using http://www.css3.info/preview/box-shadow/

Ruby on Rails: apply drop shadow with Carrierwave - Stack Overflow

ruby-on-rails carrierwave
Rectangle 27 0

The uploaders (as well as the models) have no idea of the current_user variable made by devise, that only works for controllers and views.

The way I would solve that would be to empty your store_dir method:

def store_dir
    ""
end

And then go to your controller and assign your preferred key to the "key" attribute of your uploader object:

@uploader = @model.uploader_mounted_as
@uploader.key = "uploads\/#{current_user.id}\/#{model.id}/\${filename}"
"uploads/1/2/image.png"
image.png

ruby on rails - Changing CarrierWave file upload location - Stack Over...

ruby-on-rails file-upload carrierwave
Rectangle 27 0

Upload images to the cloud with carrierwave [Ruby-on-Rails and fog] ...

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# carrierwave use imagemagick
gem 'rmagick'
gem 'carrierwave'

# interact with various cloud services
gem 'fog'
Ruby-on-Rails fog carrierwave
Rectangle 27 0

I had came up with the same problem earlier but didn't found any solution. What i did is here

<%= form_for(@article) do |f| %>
  <div class="field">
    <%= f.text_area :content, placeholder: "Compose new article..." %>
    <%= f.fields_for :photos, @article.photos do |p| %>
      <%= p.hidden_field :article_id %>
      <%= p.label :image %>
      <% if p.object.image %>
        <%= image_tag p.object.image.url %>
        <p><%= p.object.image.file.filename %></p>
      <% end %>
      <%= p.file_field :image %>
    <% end %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

Even if you try to set the image file name to file_field via js , you will get following error

Thanks, Rahul Singh. The file name and image are displayed!! But I'd also like to know how to display the file name instead of the message "no file selected".

one way to do is, hide the file field and add a button, and click on file_field via js on click of button. and replace the filename with the newly selected file via js too.

I haven't tried your latest comment, But I found out that NoMethodError in Articles#new "undefined method 'filename' for nil:NilClass" in <%= p.object.image.file.filename %> when I call new.html.erb which has <%= render 'shared/article_form' %> same as articles\edit.html.erb.

change if condition with <% if p.object.image and p.object.image.file %>

ruby on rails - Rails4 : How do I display and edit uploaded file using...

ruby-on-rails ruby-on-rails-4 carrierwave
Rectangle 27 0

where uploaded_io is your $_FILES variable and 'app_banners' is folder under assets

where image.png is put in any folder in assets auto detect and display.. on your webpage..

ruby - Rails 3: How to save uploaded images to assets directory and ho...

ruby-on-rails ruby imagemagick carrierwave
Rectangle 27 0

@adamonduty's solution is great. Another solution I used before, just create a method on the model:

def name
    file.path.split("/").last
  end

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

before_save :update_file_attributes


  def update_file_attributes
    if file.present? && file_changed? 
      self.content_type = file.file.content_type
      self.file_size = file.file.size
      self.file_name = read_attribute(:file)
    end
  end

ruby on rails - Displaying a Carrierwave filename in the view - Stack ...

ruby-on-rails ruby-on-rails-3 carrierwave
Rectangle 27 0

You could have used the file_identifier method, in your case:

comment.file_identifier

ruby on rails - Is there a better way to display the filename in carri...

ruby-on-rails ruby ruby-on-rails-3 carrierwave
Rectangle 27 0

I may be wrong but I'm sure in this case you would just do

image_tag model.mount.version.url

If there is no version or file then carrierwave uses the default url

that didn't do ti sadly but thx for suggestion

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

ruby on rails - carrierwave default_url how to display in views? - Sta...

ruby-on-rails ruby-on-rails-3 activerecord upload carrierwave
Rectangle 27 0

Image.new.file.url(:version)

Where Image is my model where I'm attaching uploader to the file field. Hope it helps.

ruby on rails - carrierwave default_url how to display in views? - Sta...

ruby-on-rails ruby-on-rails-3 activerecord upload carrierwave
Rectangle 27 0

Cropping images with carrierwave [Ruby-on-Rails and jcrop]

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# carrierwave use rmagick
gem 'rmagick'
gem 'carrierwave'
gem 'jcrop-rails-v2'
Ruby-on-Rails carrierwave jcrop
Rectangle 27 0

how to check that its a time zone issue and and what time zone need to set and how to set time zone at heroku ?

Time zone is an application setting, in config/application.rb. See here. If your dyno time is skewed, you have no choice but to re-deploy and hope it doesn't happen again, or follow geemus' advice re sync_clock. For others trying to catch up, see groups.google.com/forum/#!topic/ruby-fog/kaehIbyr3kk

Yeah, as @Taavo notes, I would expect it to be unusual to get a skewed dyno, so a re-deploy would likely also fix it. sync_clock ensures it, but is probably not often most of the time.

how to apply sync_clock option on S3 upload with CarrierWave in Ruby O...

ruby-on-rails ruby-on-rails-3 amazon-s3 carrierwave fog