Post rails upgrade from rails 4 too rails 5 font awesome loading path is not correct for more understanding
My Application.css path(correct path)
https://s3_domain/s3_bucket_name/project_name/assets/admin-fingerprint.css
Request Method: GET
Rendered 403 font awesome
https://s3_domain/assets/fontawesome-webfont-fingerprint.woff2
Request Method: GET
Ideally correct path should be->
https://s3_domain/s3_bucket_name/project_name/assets/fontawesome-webfont-fingerprint.woff2
Request Method: GET
related gems in my project
* autoprefixer-rails (10.4.7.0)
* font-awesome-rails (4.7.0.8)
* jquery-fileupload-rails (1.0.0)
* jquery-minicolors-rails (2.2.6.2)
* jquery-rails (4.5.0)
* minitest-rails (3.0.0)
* pry-rails (0.3.9)
* rails (5.1.0)
* sass-rails (6.0.0)
* sassc (2.4.0)
* sassc-rails (2.1.2)
* slim-rails (3.5.1)
* sprockets-rails (3.2.2)
I've used paperclip in the past with AWS S3 storage, but with this project I'm trying to reduce external dependencies. I'd like to save uploaded images to the public/assets directory, for immediate use (skirting asset pipeline). Here's the error I'm getting when it tries to save:
Errno::EPERM in PostsController#update
Operation not permitted - /usr/local/src/project_name/public/assets/
...
app/controllers/posts_controller.rb:43:in `update'
I've chmod'ed the directories to 755, as suggested in an existing Stack Overflow solution. That shouldn't even matter though, because thin (my web server) is running as root (via sudo) so that I can bind to 443 (HTTPS). I don't understand why would there even be a permission error for root. What am I not getting? Is the file being uploaded by the user under an anonymous public account, or is the application server saving it as root?
Additional info:
Environment: Development
Operating System: OS X 10.9.3
Ruby version:
MRI ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
Gem versions:
Gems included by the bundle:
* actionmailer (4.0.3)
* actionpack (4.0.3)
* activemodel (4.0.3)
* activerecord (4.0.3)
* activerecord-deprecated_finders (1.0.3)
* activesupport (4.0.3)
* acts-as-taggable-on (3.2.6)
* arel (4.0.2)
* atomic (1.1.15)
* bcrypt (3.1.7)
* bcrypt-ruby (3.1.5)
* builder (3.1.4)
* bundler (1.5.3)
* climate_control (0.0.3)
* cocaine (0.5.3)
* coffee-rails (4.0.1)
* coffee-script (2.2.0)
* coffee-script-source (1.7.0)
* daemons (1.1.9)
* epiceditor (0.2.2.1)
* erubis (2.7.0)
* eventmachine (1.0.3)
* execjs (2.0.2)
* faraday (0.9.0)
* friendly_id (5.0.4)
* haml (4.0.5)
* haml-rails (0.5.3)
* hike (1.2.3)
* i18n (0.6.9)
* jquery-rails (3.1.0)
* json (1.8.1)
* jwt (1.0.0)
* mail (2.5.4)
* mime-types (1.25.1)
* minitest (4.7.5)
* multi_json (1.8.4)
* multi_xml (0.5.5)
* multipart-post (2.0.0)
* oauth (0.4.7)
* oauth2 (0.9.4)
* paperclip (4.1.1)
* polyglot (0.3.4)
* rack (1.5.2)
* rack-test (0.6.2)
* rails (4.0.3)
* railties (4.0.3)
* rake (10.1.1)
* rdiscount (2.1.7.1)
* sass (3.2.14)
* sass-rails (4.0.1)
* sorcery (0.8.5)
* sprockets (2.11.0)
* sprockets-rails (2.0.1)
* sqlite3 (1.3.9)
* thin (1.6.2)
* thor (0.18.1)
* thread_safe (0.2.0)
* tilt (1.4.1)
* treetop (1.4.15)
* tzinfo (0.3.38)
* uglifier (2.4.0)
File permissions (via ls -la public):
drwxr-xr-x 9 proto admin 306 Jul 6 15:16 .
drwxr-xr-x 23 proto admin 782 Mar 28 06:24 assets
Server Daemon (via ps aux | grep [t]hin):
root 2650 0.0 0.9 2513704 79120 ?? S 3:43PM 0:07.81 thin server (0.0.0.0:443)
Post model:
class Post < ActiveRecord::Base
# Relationships
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
has_attached_file :photo,
path: ':rails_root/public/assets/',
url: ':basename.:extension'
belongs_to :author
# Validations
validates_presence_of :title, :body, :author_id, :slug
validates_uniqueness_of :slug
validates_attachment_content_type :photo, content_type: /\Aimage\/.*\Z/
# Overriding this friendly method to update slug when title changes
def should_generate_new_friendly_id?
slug.blank? || title_changed?
end
end
Update action:
def update
#data = {
title: params[:post][:title],
body: params[:post][:body],
photo: params[:post][:photo]
}
if #post.update! #data
redirect_to #post
else
render :edit, layout: 'layouts/admin'
end
end
Form partial:
= form_for post, html: { multipart: true } do |f|
= f.text_field :title, placeholder: 'Title'
%br
= f.text_area :body, class: 'hidden'
#epiceditor
%br
= f.submit 'Save', class: 'button'
- unless post.new_record?
= link_to 'Delete', post, method: 'delete', class: 'button'
= f.file_field :photo, class: 'upload'
- unless post.photo.nil?
= link_to post.photo.url, post.photo.url
This is too long to write as a comment, but you could use other port than 443, which the root will redirect to from port 443, using, let's say, iptables.
$ sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
Then you can start your server normally, as rails user, on port 8443
This is of course if you want to do so.
Regarding the comment/question I've asked to your question, I'm not familiar with thin server, but I would consider the case where the application is running as rails user (proton?) and the frontend web server as root. In that case, root owned assets folder will probably not writeable for rails user....
Change the permissions on public folder to 775.
Update
You might find your solution here: Errno::EPERM (Operation not permitted FILE_PATH) when uploading image with Rails, Carrierwave, Amazon EC2
Looks like you might need to change the owner of public/assets to root (or whichever user the application is running as).
How can I handle the error:
OmniAuth::Strategies::OAuth2::CallbackError
...generated by OmniAuth when a user goes through to the Facebook login, but decides to cancel?
I have seen a few threads about this, but none of the solutions worked for me.
I tried placing this:
OmniAuth.config.on_failure = UsersController.action(:oauth_failure)
...into the omniauth.rb initializer file with no success.
I am using the omniauth-facebook gem with Rails 4.0.2.
Any help greatly appreciated.
Many thanks!
Michael.
My gemfile.lock file reveals the following gems related to the omniauth-facebook gem:
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.4)
hashie (>= 1.2, < 3)
rack
omniauth-facebook (1.5.1)
omniauth-oauth2 (~> 1.1.0)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
I upgraded the omniauth-facebook gem to version 1.0.6 and now it is working as expected.
For anyone else coming across this issue and would like to capture this error, here's what you need:
/config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'xxx', 'xxx', scope: "email,publish_stream,user_location,user_birthday"
end
/config/initializers/omniauth_failure_callback.rb
OmniAuth.config.on_failure = Proc.new do |env|
UsersController.action(:omniauth_failure).call(env)
end
/app/controllers/users_controller.rb
def omniauth_failure
flash[:danger] = "Unable to connect with Facebook at this time."
redirect_to root_url
end
Trying to add Gravatar to my app
but get "could not find generator gravtastic" on the command line
added gem 'gravtastic'
ran bundle install
Using warden (1.2.3)
Using devise (3.1.2)
Using foreigner (1.6.1)
Installing gravtastic (3.2.6)
Using hike (1.2.3)
Using jbuilder (1.0.2)
Using jquery-rails (3.0.4)
Using subexec (0.2.3)
restarted server
rails g gravtastic:install
Could not find generator gravtastic
Do you need to run a generator?
I think you just have to do:
class User < ActiveRecord::Base
include Gravtastic
gravtastic
end
The documentation doesn't mention the gravtastic generator.
I develop a new application and I want to transfer users from old one. I'd like to let them to use their own old password in new app.
OLD_APP:
config.encryptor = :authlogic_sha512
config.pepper = "xxx"
devise (1.1.7)
bcrypt-ruby (~> 2.1.2)
warden (~> 1.0.2)
NEW_APP:
devise (2.2.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.2.1)
BCrypt
without pepper (config.pepper line left commented)
I used some solutions such as:
Converting existing password hash to Devise
but unfortunately it doesn't works.
My questions is how I could transform SHA512 hash (with salt) to BCrypt (without salt) ?
Whether anybody came across on this issue ?
Thanks.