Home>
I am implementing an edit page (edit action) for a site where you can list items.
Multiple images (image models) can be registered for products (product models), and images models are nested.
When accessing the edit page, the registered image is displayed in the form, and the saved image is displayed. Even if the image is not changed, the value is set in image_url when the update button is pressed. The following error will be displayed without.
ActiveRecord :: NotNullViolation in ProductsController # update
Error screen
https://gyazo.com/19831190041103672cdd7c656d281304
I use carrierwave to upload images
Probably, the image part is not correctly specified by the strong parameter of the controller.
.new-conteiner
= render 'shared/new_header'
.new-main
.new-main__box
% h2 Enter product information
= form_for @product do | f |
.image
% h4 exhibition image
.image__images
= f.fields_for: images do | image |
.image__images__box {"data-image-id": "# {image.object.id}"}
= image.file_field: image_url, class: "file-field", style: "display: none;", id: "edit-file", value: "# {image.object.image_url.url}"
= image_tag (image.object.image_url.url, id: "product_image", height: '120', width: '120')
= image.hidden_field: id, value: image.object.id
.edit_btns
.change_btn
.change_btn-text edit
.delete_btn
.delete_btn-text delete
def edit
@product = Product.find (params [: id])
@user = current_user
@images = Image.where (product_id: @product)
@category_parent_array = ["---"]
Category.where (ancestry: nil) .each do | parent |
@category_parent_array<<parent.name
end
end
def update
if @ product.update (product_params)
redirect_to product_path
else
render 'buyer_show'
end
end
private
def product_params
params.require (: product) .permit (
: title,: image,: text,: price,: saler_id, {categories: []},
images_attributes: [: image_url,: id],-# It seems that this part is not specified correctly
condition_attributes: [: condition],
freight_attributes: [: freight],
root_area_attributes: [: root_area],
day_attributes: [: day]
class Product
class Image
-
Answer # 1
Related articles
- ruby on rails 5 - rails cannot retrieve params data
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs
- ruby - apprb cannot be started is there a problem with require'sinatra'? ?? ??
- javascript - i want to display the contents of an associative array and a combination of arrays
- ruby - asynchronous communication of like function cannot be implemented
- dart - i want to check the contents of an array in flutter, but i get an error
- ruby - logout function cannot be implemented
- ruby - rails5 array contains unintended backslashes
- ruby on rails - data cannot be saved in the intermediate table (parameters cannot be passed)
- ruby on rails - cannot pass id to destroy action of intermediate table
- ruby on rails runtime error cannot be resolved
- ruby - i entered secret_key_base, but http error 500 cannot be resolved
- ruby on rails 5 - the time notation cannot be written normally
- ruby on rails 5 - actioncontroller :: invalidauthenticitytoken cannot be resolved
- ruby nokogiri some parts cannot be obtained
- ruby - questions about the contents of the aws reference site
- sort hashes in a ruby array by value
- ruby - cannot save to database
- ruby - the method defined in the model cannot be used
- ruby - [rails] when rails s is executed, an error "cannot load database configuration" appears and it is forcibly term
Related questions
- ruby - passing variables using render partial
- ruby - #i want to see a list of posts for that user on the user details page
- ruby - implementation of friendly forwarding
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs
- ruby - if i include the'omniauth-facebook'gem, do i need to install the'omniauth' gem as well?
To view
= image.hidden_field: image_url, value: image.object.image_url
I was able to save it by erasing it!