ruby-on-rails-6

Getting Jquery and Bootstrap to work with Rails 6

不想你离开。 提交于 2019-12-24 00:55:38
问题 I am a new to rails and struggling to get Jquery and Bootstrap to work with Rails 6. I think it has something to do with switching the app from rails 5 to rails 6 and using webpacker to load Jquery rather than loading it as a gem. I have gone through the instructions for this however it still doesn't seem to work properly. Someone helped me with a more specific problem and got me to paste this into the view which then seemed to make it work: <script src="https://code.jquery.com/jquery-3.3.1

Is there a way to test if PostCSS Autoprefixer is working? Specifically for Rails 6

*爱你&永不变心* 提交于 2019-12-23 17:24:03
问题 I am writing a Rails 6 webapp using Webpacker. Its my understanding that auto-prefixing in Rails 6 works out of the box via PostCSS and its autoprefixer plugin. However I cannot verify if this library is in fact prefixing my css or not. Is there a way to confirm if a standard default Rails 6.0.0 app auto-prefixes out of the box? I have run yarn autoprefixer --info to see the css rules and browsers it applies to and its def applying to my browser chrome 77 . And I tried using a parameter that

How can I preload concerns in a rails initializer using Rails 6/Zeitwerk?

我与影子孤独终老i 提交于 2019-12-23 09:40:06
问题 I'm working with an initializer that does some monkey patching on app start by including some app concerns into a third party lib. Basically: # config/initializers/my_initializer.rb class SomeExternalLib include MyConcern1 include MyConcern2 end This works fine in Rails 5.2.3, but I got the following deprecation message when upgrading to Rails 6: DEPRECATION WARNING: Initialization autoloaded the constants MyConcern1, and MyConcern2. Being able to do this is deprecated. Autoloading during

When using activestorage in Rails 6, how do I retain a file when redisplaying a form?

蓝咒 提交于 2019-12-22 18:03:08
问题 In Rails 6 I have a form with a file field and I am using activestorage to store the file. If validations fail after submitting the form, the form is redisplayed showing the validation errors. How can I retain the file added to the file field when redisplaying the form so that the user does not have to add the file again to the form? There is already a similar question for rails 5: Active Storage: Best practice to retain/cache uploaded file when form redisplays, however the solution there

Rails ActiveStorage: how to avoid one redirect for each image?

对着背影说爱祢 提交于 2019-12-22 17:44:09
问题 If you use ActiveStorage and you have a page with N images you get N additional requests to your Rails app (i.e. N redirects). That means wasting a lot of server resources if you have tens of images on a page. I know that the redirect is useful for signed URLs. However I wonder why Rails does not precompute the final signed URL and embed that into the HTML page... In this way we could keep the advantages of signed URLs / protected files, without making N additional calls to the Rails server.

Rails 6: Only one profile per user should be created

☆樱花仙子☆ 提交于 2019-12-19 12:23:58
问题 I'm currently working on a Rails 6 application. I have the following association. A User has a Profile and a Profile belongs to a User. When editing a profile for a user I ended up having two profiles for the user. I would like to have only one profile per user. Edit form: profile/edit.html.erb <%= form_for @profile do |f| %> <div class="form-group"> <%= f.label :avatar %> <%= f.file_field :avatar, as: :file, class: "form-control" %> </div> <div class="form-group"> <%= f.label :full_name,

How to require custom JS files in Rails 6

早过忘川 提交于 2019-12-18 19:03:19
问题 I'm currently trying Rails 6.0.0.rc1 which seems to have moved the default javascript folder from app/assets/javascript to app/javascript . The application.js file is now located in app/javascript/packs . Now, I want to add a couple of js files, but for some reason they don't get imported and I can't find any documentation on how this can be done in Rails 6. I tried a couple of things: Create a new folder custom_js under app/javascript/packs , putting all my js files there and then add a

Rails Edit action not updating and not work properly using Ajax

雨燕双飞 提交于 2019-12-13 03:46:34
问题 I am trying to do two things : With Ajax render Edit form when a user clicks on Edit link/button Then after editing and they click on Update link/button, hide the form. ...but unfortunately, it didn't behave that way. It perfectly renders the form through Ajax but... it renders the form on all of the rows. after edit and you click update it doesn't hide the form. Below is the code: controller before_action :set_clock_entry, only: [:edit, :update] def edit end def update respond_to do |format|

Vanilla Rails 6.0: “error Command ”webpack“ not found”

ⅰ亾dé卋堺 提交于 2019-12-07 03:03:50
问题 System: Ruby: 2.6.3p62 (rvm) Rails: 6.0 OS: macOS 10.14.6 Setup A fresh Rails 6.0 application: $ rails new testshop2 $ cd testshop2 $ rails g controller Page index $ rails s => Booting Puma => Rails 6.0.0 application starting in development => Run `rails server --help` for more startup options Puma starting in single mode... * Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Use Ctrl-C

Using ERB in Markdown with Redcarpet

岁酱吖の 提交于 2019-12-06 05:13:43
问题 I'm trying to get Markdown to play nicely with .erb. I'd like to use high_voltage to render markdown pages (or normal .html.erb files with markdown partials) that are parsed with Redcarpet and am struggling to get it to all work together. At the moment I have an initializer called markdown_template_handler.rb that contains the following code: class MarkdownTemplateHandler def erb @erb ||= ActionView::Template.registered_template_handler(:erb) end def call(template) compiled_source = erb.call