Home>
I'm new to Ruby on rails.
Currently, I am building an EC site, and what I stumbled upon was the process of registering in the DB.
I'm thinking of realizing array registration using nested images (plural) and intermediate tables at once.
NameError in ProductsController # create
uninitialized constant Product :: ProductTag
# Product registration
def create
@product_resister = Product.new (product_tag_image_params) Red line (error location)
if @ product_resister.save
flash [: success] = "Product registration is complete."
redirect_to products_path
The product is not registered in the table.
Looking at the log, I was able to implement it up to the point where it was sent in an array firmly,
I think that the SQL statement may not be issued when saving to the table (or just before that).
(views/products/new.html.erb) Partially described
Enter the information of the product I want to register here (multiple tags can be selected below)
<% = Form_for @product_resister, html: {class: "new_product"} do | f |%>
<% = F.label: tag, "tag", class: "form_field"%>
<% = collection_check_boxes (: product,: tag_ids, Tag.all,: id,: name) do | tag |%>
<% = tag.label do%>
<% = tag.check_box%>
<% = tag.text%>
<% end%>
<% end%>
<% = f.submit "register", class: "resister_btn"%>
<% end%>
(controllers/products_controller.rb) Partially described
I'm trying to save an array of nested images and selected tags (s) using strong parameters.
# Product registration page
def new
@product_resister = Product.new
@image = @ product_resister.images.build
end
# Product registration
def create
@product_resister = Product.new (product_tag_image_params)
if @ product_resister.save
flash [: success] = "Product registration is complete."
redirect_to products_path
else else
flash [: danger] = "The product could not be registered. Sorry to trouble you, but please register again."
render "new"
end
end
private
def product_tag_image_params
params.require (: product) .permit (: name,: price,: count,: category,: content,: comment, images_attributes:
[
: id,: img1,: img2,: img3,: img4,: img5
],,
tag_ids: []
)
end
(models/tag.rb)
class Tag
(models/products_tag.rb)
class ProductsTag
(models/order.rb) * Partially described
class Product
-
Answer # 1
Related articles
- ruby on rails 6 - [error] uninitialized constant user (call'userconnection' to establish a connection) :: image
- ruby on rails 6 - [rails]'unfollow' function does not work * no error message
- ruby on rails - i don't understand the content of the error
- ruby - nameerror uninitialized constant drinkscontroller :: drinktag
- ruby on rails - i want to put what i posted on the show page, but it's a blank page it's not an error
- ruby on rails - rspec test changed by -1, but was changed by 0 error
- ruby on rails 6 - [error] nomethoderror in followscontroller # destroy undefined method `destroy'for nil: nilclass
- ruby - when i try to update rails, i get a routing error
- ruby - [rails] about the error that occurs when deleting likes (routing error)
- ruby on rails - i get an error in a program that changes over time
- ruby on rails - i get an error with rails db: create
- ruby on rails 5 - i want to get an error message when i enter the user id in full-width in url
- ruby on rails - pg :: datatypemismatch error when doing heroku run rails db: migrate
- ruby on rails 6 - about rails error "wrong number of arguments (given 1, expected 0)"
- ruby on rails - nomethoderror in itemscontroller # new error
- ruby on rails - i get an error without being created
- ruby on rails 6 - when i press new user registration, i get an error of no route matches [get] "/ users"
- ruby on rails - i get a template is missing error in render
- solution for ruby on rails routes error
Related questions
- ruby - i want to get records that match multiple foreign keys from within an intermediate table
- ruby - about how to save db with rails devise
- ruby - when i try to save data from rails console, id, created_at, updated_at become nil
- how to write in ruby multiple loop controller
- ruby - output the total integer value held by each user
- ruby - i want to use two rails renders
- ruby - i can't get a payjp token on aws
- html - i want it to be rendered if the search word is incorrect
- ruby - about viewport introduction
- ruby - [rails] about the error that occurs when deleting likes (routing error)
The error message is as follows.
ProductTag
There is no intermediate model called.has_many: product_tags
Even though it is, the existing model isProductsTag
It has become. Check the table name and match it to the correct one.