ruby-on-rails-5

Adding an image_tag for the inline background-image url in Rails 5 template

我是研究僧i 提交于 2021-01-28 10:42:15
问题 I need to set the background image inline using the style tag, but it needs to reference an image object and not a fixed image from the assets folder. Below is my code to show what I am attempting to do. <div class="background-image-holder" style="background: url(#{" image_path @product.photo_one_url(:original)"}); opacity: 1;"> <%= image_tag(@product.photo_one_url(:medium)) %> </div> 回答1: I always prefer to use a content_tag if I'm including something dynamic like this, i.e. <%= content_tag

Toggle “ActionController::Parameters.action_on_unpermitted_parameters = :raise” on specific controller methods?

陌路散爱 提交于 2021-01-28 04:31:33
问题 I want to use ActionController::Parameters.action_on_unpermitted_parameters = :raise To raise an exception unpermitted parameters are passed in, but I only want to do this on specific controller methods, instead of setting it in /config/ and having it apply to the whole environment. Is there any way to do so? 回答1: Update : (taking inspiration from Mike's answer) To restrict the change only for a set of controller actions and to revert it back to the original value that the class attribute was

unable to push to Heroku after importing thousands of records

瘦欲@ 提交于 2021-01-27 22:02:18
问题 I have a problem where I believe my sqlite3 database is too big. I imported around 100,000 records into a database and I was able to "git push" and "git push heroku." Now I probably made a mistake and imported too many records...500,000. I was able to push to git(and now it states around 336MB in bitbucket) and that seems to work but when i push to heroku this is what i get: /workspace/new_foodback$ git push heroku Counting objects: 26, done. Delta compression using up to 8 threads.

How to save a nested resource in ActiveRecord using a single form (Ruby on Rails 5)

☆樱花仙子☆ 提交于 2021-01-04 09:14:15
问题 I have two entities with a many-to-one relationship. User has many Addresses. When creating a User I want the form to also create a single Address. The entities are nested. Approach 1: The code below works, but only saves the User, no associated Address. Reading around, I thought that the accepts_nested_attributes_for would automatically save the address. I'm not sure, but it may be that this isn't working because the parameters I'm getting into the Controller don't actually appear to be

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-29 12:15:21
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

心不动则不痛 提交于 2020-12-29 12:13:45
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

南笙酒味 提交于 2020-12-29 12:12:27
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

佐手、 提交于 2020-12-29 12:09:13
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

狂风中的少年 提交于 2020-12-29 12:08:33
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do

PG::ForeignKeyViolation: ERROR: update or delete on table “xxx” violates foreign key constraint

旧街凉风 提交于 2020-12-29 12:08:17
问题 I have several tables that have foreign key constraints associated with them, each referencing the other in a hierarchical fashion as outlined below. When I try to destroy a Company that has at least 1 Project, that has at least 1 Task, that has at least 1 TaskTime like so... irb(main):014:0> Company.first.destroy I get the below output and error. I am under the impression now that simply having dependent: :delete_all doesn't deal with the foreign key constraints, is this true? If so, how do