ruby-on-rails-5

rails 5 form_tag with original DB value and after new selection in form, both records must be updated

天大地大妈咪最大 提交于 2019-12-25 04:26:15
问题 I have a form_tag with a radio_button_tag and it populates with data from DB. It must simply be directed to a customised update action(update_multiple) where a boolean column is updated for all those 2 records which have been changed in the form. For e.g. say when initially the form was populated from DB with record 1's radio button selected and now user changed his selection to record 3, then at Submit of form tag the update of both records must occur but the problem is the code at submit,

Update Each Array-Object Value in Rails

a 夏天 提交于 2019-12-25 04:02:35
问题 Basically I want to update each table column for a Model in Rails 5. str = "abc---def" str.split('---').map do |a| Foo.where(product_id:1).update_all(bar: a) end Old object would be like: [ [0] { product_id: 1, ..., bar: "xxx", ... }, [1] { product_id: 1, ..., bar: "xxx", ... } ] New should be like: [ [0] { product_id: 1, ..., bar: "abc", ... }, [1] { product_id: 1, ..., bar: "def", ... } ] But what I got is bar: "def" for each. Is there a clean method in rails to achieve what I want? update

Update Each Array-Object Value in Rails

时间秒杀一切 提交于 2019-12-25 04:01:17
问题 Basically I want to update each table column for a Model in Rails 5. str = "abc---def" str.split('---').map do |a| Foo.where(product_id:1).update_all(bar: a) end Old object would be like: [ [0] { product_id: 1, ..., bar: "xxx", ... }, [1] { product_id: 1, ..., bar: "xxx", ... } ] New should be like: [ [0] { product_id: 1, ..., bar: "abc", ... }, [1] { product_id: 1, ..., bar: "def", ... } ] But what I got is bar: "def" for each. Is there a clean method in rails to achieve what I want? update

Open tracking not working with Rails ahoy_email gem

不打扰是莪最后的温柔 提交于 2019-12-25 03:06:25
问题 I am using ahoy_email gem in Rails and I am unable to make simple open tracking work, and I don't know how to debug it. The message record is being generated when email is sent: #<Ahoy::Message:0x000055592a4bd3a8 id: 1, token: "AVKoHmuT0OxqaQRpMfNoDjzD3ibUltHL", to: "augusto@qounter.com", user_type: "User", user_id: 6, mailer: "UserMailer#welcome_email", subject: "Bienvendido al Sistema de Facturación de Megacentro", sent_at: Thu, 30 Aug 2018 21:35:44 UTC +00:00, opened_at: nil, clicked_at:

Rails 5.1 group_by year and month and show both

隐身守侯 提交于 2019-12-25 00:33:36
问题 I'm working on a rails app for my expenses. I have 3 models like : user, spending and currency. I can create a spending via form, I have a title, description, amount, currency_id, user_id. All the relations are made and working. I use my show.html.erb from the user controller to display all the expenses from the current_user. That works fine. I then I grouped the expenses together and sort them by date. I did actually 2 groups, the first one which is today and the rest. So on the display it

List all associated model records present in another model present in another namespace in rails

只谈情不闲聊 提交于 2019-12-25 00:29:35
问题 I have two models like: class Superadmin::Company < ApplicationRecord belongs_to :user has_many :garments end 2nd class Garment < ApplicationRecord belongs_to :company ,:class_name => "Superadmin::Company" end But when I search like company = Superadmin::Company.find(9) company.garments Its give error: as Garment Load (1.3ms) SELECT `garments`.* FROM `garments` WHERE `garments`.`company_id` = 9 ORDER BY created_at asc ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'garments

Links do not work after translation into slim format

梦想与她 提交于 2019-12-25 00:00:09
问题 I have an html code with rails. I need to translate it into slim format, I changed the file format, translated it with a convector and tried to run it as a result the links do not work, can you tell me why? head.html.erb <section id="header"> <div class='navigation-panel'> <button class='burger-button' id='header-burger-button container' onclick='burgerAction()'> <%= image_tag("header/burger.png") %> </button> <button class='contact-us-button burger-hidable container' onclick='scroller(

How can I temporarily store (cache) images before uploading to S3?

谁都会走 提交于 2019-12-24 22:47:02
问题 My rails app is using CarrierWave and Fog to upload images to S3. Remote URLs are working fine, HOWEVER I need to temporarily store local images (from the device it's being uploaded) before I can upload these local images to S3. How do I go about this? How do I cache my images? Vision table: class CreateVisions < ActiveRecord::Migration[5.1] def change create_table :visions do |t| t.string :image t.text :description t.timestamps end end end Vision model: class Vision < ApplicationRecord

Rails 5, devise nested attributes, unpermitted parameters

梦想与她 提交于 2019-12-24 20:52:38
问题 I'm using Devise in my Ruby on Rails application. When users signs up or updates their account I also want to create / update their AddressInformation . class User < ApplicationRecord belongs_to :address_information accepts_nested_attributes_for :address_information, allow_destroy: true [...] My _form.html.haml looks like this: = form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| = devise_error_messages! .form-group = f.label :name = f.text_field :name = f

How to test a Webpack bundle that has external dependencies?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 20:12:07
问题 I'm new to Webpacker and Rails in general. I recently moved to using Webpacker to bundle React components. Since part of the application still uses the asset pipeline, some dependencies are still stored in vendor/assets/javascript , and accessible as globals. The Webpack bundle declares those dependencies as external, and when serving the app, everything works great, as Rails serves the dependencies, which are then picked up by the bundle. Now I want to start testing the bundle using