Can you upload files in a Rails 6 form with remote: true?
My form has remote: true and multipart:true, and works without issue when I do not upload any files.
Once I try to upload a file, I get a 406 error, and in my logs I'm seeing:
ActionController::UnknownFormat (AppProxy::RegistriesController£update is missing a template for this request format and variant.
request.formats: ["text/html"]
It seems only when I try to upload an image, I'm getting this error, otherwise my update.js.erb is running fine when other fields are saved and no files are uploaded.
Edit: It appears that the uploads are in fact saving despite the error, but I'm still only seeing this error when the form has uploads.
I assumed remotipart wasn't going to work because it explicitly says it's for Rails 3 and 4, but alas, it did work for me.
add gem 'remotipart' in Gemfile
//= require jquery.remotipart
add this line in app/assets/javascripts/application.js (right after //= require jquery_ujs):
Related
I upgraded Rails 4.2.10 application to Rails 5. Solved errors with bundling and some deprecations. I am able to start the Rails Application, but when I try to load the Application, it fails with error, Invalid CSS after "#": expected id name, was "= require in the css file
I tried using #import, but it fails for external files in vendor/assets. Nevertheless, I want to understand why it isnt working anymore. In my config, I have the file in config.assets.precompile +=
In my index.html.erb,
<%= stylesheet_link_tag 'users' %>
In users.scss,
#= require "dashboard/dx"
Note: I am using sass-rails in my Gemfile
The error that I get,
Sass::SyntaxError in Dashboard::Users#index
Invalid CSS after "#": expected id name, was "= require "dash..."
Extracted source (around line #1):
#= require "dashboard/dx"
Hey I think the error is throwing because in your typical .scss file you would have to use either an #import "dashboard/dx" and#= requiremight only work in.css`
The problem with this line
#= require "dashboard/dx"
This syntax is not working with .scss file. Either You have to write like this
#import 'dashboard/dx'
Or rename the file with .css extension.
Note: You can also try to rename with .css.scss extension May be it works also sometimes.
I have difficulties integrating select2-rails with ActiveAdmin. I followed setup steps on
Select2-rails Github page: https://github.com/argerim/select2-rails and I added line:
//= require select2
to app/assets/javascripts/application.js and line:
*= require select2
to app/assets/stylesheets/application.css
so I assume when I have page in ActiveAdmin I should be able to add line:
$('#add_student_select').select2()
to active_admin.js.coffee
But its not working. In console I can see following error:
Uncaught TypeError: undefined is not a function
(anonymous function)
fire
self.fireWith
jQuery.extend.ready
completed
I also followed this StackOverflow question which recommends to add this line to active_admin.css.scss:
body.active_admin {
#import "select2";
}
But then I get following error:
File to import not found or unreadable: select2.
Do I integrate it correctly? I don't think that ActiveAdmin is able to get even access to the librabry.
If you're adding Select2 to the ActiveAdmin interface, you must add the javascript and styles to the ActiveAdmin assets:
# app/assets/javascripts/active_admin.js.coffee
#
#= require select2
#
# ...
And the stylesheets:
// app/assets/stylesheets/active_admin.css.scss
//
//= require select2
//
// ...
In the example you provided, Select2 would be available to the main Rails application, but not ActiveAdmin. ActiveAdmin uses its own javascript and stylesheet files.
I had met the same issue making select2 work with activeadmin, but instead I used a gem named activeadmin-select2. I had installed it according to the README, but I still got error "File to import not found or unreadable: select2.". It seems like that select2-rails had not been installed or not be accessible, however. So then I tried to add select2-rails to my Gemfile, and bundle, lastly, everything went well. You should checked your gem loading before you can make it work.
I am running Rails 4.0.1 and Ruby 2.0.0. I currently have a graph.js that takes inputs in from the user for a savings calculator in order to create a graph with d3 and the rickshaw.js graph.
My graph.js file is saved in the app/assets/javascripts/graph.js. I make a call to the Rickshaw graph with
var graph = new Rickshaw.Graph()
I am getting an error of Uncaught ReferenceError: Rickshaw is not defined.
The rickshaw.js file is saved in vendor/javascript/rickshaw.js along with d3.layout.js and d3.vs.js. If I save all of these files in the app/assets/javascripts everything works fine, but that does not seem to be the correct rails way.
Does anyone know how to fix this error?
Thank you.
To use the asset pipeline, you'll want just the filename in the require statements:
// Vendor Files
//= require d3.v3
//= require d3.layout
//= require rickshaw
See the asset pipeline docs for more info on asset organization.
I'm using Rails 3.2.8. When the app is deployed access the view that is including a javascript:
<%= javascript_include_tag "epiceditor" %>
Heroku fails with this log:
ActionView::Template::Error (/app/app/assets/javascripts/epiceditor.js.erb has already been required
I've checked some possible solutions, like checking for any reference that may trigger a circular dependency, or simply removing it in case it is being included somewhere else, which isn't. So, if I include it, I get this "has already been included error", if I don't , then the file isn't included at all.
My config/application.rg has this
config.assets.initialize_on_precompile = false
And applications.js has this:
//= require jquery
//= require jquery_ujs
//= require tabs
It might be important to note that the file the tag is referencing is "epiceditor.js.erb", since it has some embedded Rails code that I needed.
Thanks for your help
EDIT:
I believe this is a bug in Sprockets. If I update Rails to 3.2.9rc2, the error is now this:
ActionView::Template::Error (Asset logical path has no extension: epiceditor/.js
but of course the extension in epiceditor is epiceditor.js.erb, and I've tried being explicit about it in the javascript_include_tag as well.
I found the bug.
It turns out that inside the .js.erb file I'm calling
<% asset_path 'epiceditor/' %>
which should expand to the path where all the epiceditor file are placed, but instead is actually loading the file itself in recursive manner. This is expanding properly in the development environment but not in the production environment. Funny, right?
The reason for this is that is adding a digest. So I fixed the whole issue with this:
<%= asset_path 'epiceditor/', :digest => false %>
and now it does expand to the directory, and doesn't fall into the recursion trap.
Hope this saves some time for someone!
After finally getting RMagick installed on my Mac I have set up attachment_fu according to the tutorial here: http://clarkware.com/cgi/blosxom/2007/02/24#FileUploadFu> when I try and upload a file via the upload form I get around 80 messages like these:
/Library/Ruby/Gems/1.8/gems/rmagick-2.13.1/lib/RMagick.rb:44: warning: already initialized constant PercentGeometry
/Library/Ruby/Gems/1.8/gems/rmagick-2.13.1/lib/RMagick.rb:45: warning: already initialized constant AspectGeometry
/Library/Ruby/Gems/1.8/gems/rmagick-2.13.1/lib/RMagick.rb:46: warning: already initialized constant LessGeometry
/Library/Ruby/Gems/1.8/gems/rmagick-2.13.1/lib/RMagick.rb:47: warning: already initialized constant GreaterGeometry
I did some searching and found that this problem can arise when you require RMagick twice in an application using different casing for the require statement: http://work.rowanhick.com/2007/12/19/require-rmagick-and-case-sensitivity/ I am not requiring it myself, but I was thinking maybe with the config.gem "rmagick" line in my environment.rb file rails might be requiring it.
After the form submits it gives me a validation error of: Content type is not included in the list
I have checked the source for attachement_fu and found the image/png in the list of content types so I don't believe that is the proper error message: http://github.com/technoweenie/attachment_fu/blob/master/lib/technoweenie/attachment_fu.rb
Does anyone have any ideas on how I can get this to work?
If, like us you're using a gem (such as gruff) which requires rmagick as above (and thus you can't really be correcting the case of the require statements), you can configure bundler to load rmagick using the matching case.
E.g. add the following to your Gemfile:
gem 'rmagick', '2.13.1', :require => 'RMagick'
That got us out of a real pickle today.
Thanks for the original post - we were lost until we read it!
Had a similar problem with Paperclip, solved by removing config.gem 'rmagick' line from environment.rb.
Update: The following only works on the Mac. My production server choked on this. Don't use it.
I came across this problem as well. In config/environment.rb I've got:
config.gem 'rmagick'
And it has to be lowercase, otherwise Rails thinks I don't have the required gem installed.
Attachment_fu has a file called rmagick_processor.rb which has the line:
require 'RMagick'
If you change this to lowercase, "require 'rmagick'", the RMagick error messages disappear.