I want to save to each table from form object through intermediate table in rails
(Image, title, text are in the articles table, tag is in the tags table)
Data is not saved when I build a local server, fill out a form and submit it
At this time, there is no error message, so I am in trouble because I can not identify the root cause.
When I submit data from the form, the screen remains the same and only what I typed disappears
It will behave as if it slips through.
Intermediate table ** article.rb ** class Article</pre> <pre><code>articles_Controller class ArticlesController</pre> <pre><code>article_tag_form.rb class ArticleTagForm include ActiveModel :: Model attr_accessor: title,: text,: tag,: image,: user_id with_options presence: true do validates: title validates: text validates: tag end def save article = Article.create (title: title, text: text, image: image, user_id: user_id) Tag.create (article_id: article.id, tag_id: tag.id) tag = Tag.where (tag: tag) .first_or_initialize tag.save end end
What I tried
tags_controller class TagsController</pre> <pre><code>View file (articles/new.html.erb) <% = form_with model: @atform, url: articles_path, class:'article-form', local: true do | f |%> ~ Abbreviation ~ <% = f.file_field: image%> <% = f.file_field: title%> <% = f.file_field: tag%> <% = f.file_field: text%> ~ Abbreviation ~ <% end%>
1) After applying binding.pry to the create action of the article controller and checking the params, the data itself (image, title, tag, text) I want to save has arrived.
2) Reconfirm the association of the intermediate table
3) Read the material of the form object and rewrite various descriptions.
ruby on rails 6.0.0
Answer # 1
Originally I wanted to implement the tag function, but I didn't solve it after all, so I decided to use the acts-as-taggable-on gem.
It ended in an instant ...
- ruby on rails - i don't understand the description of the form object pattern
- ruby on rails - get id of rails table
- ruby on rails 6 - rails does not save to intermediate table
- ruby on rails - round-robin league table design
- ruby - the last db setting doesn't work when deploying rails app on aws
- ruby on rails - i want to write a rails tutorial test in rspec
- ruby on rails - rails60 i can't log in
- 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 - [rails] the initial image of the icon for the user is not displayed
- ruby on rails - error when implementing rails6 follow function
- ruby on rails - how to debug with rails pry in docker environment
- ruby - i can't transition to my page for each user after logging out (rails)
- ruby - i want to output csv with narrowed down conditions with rails
- ruby on rails - the value of find_by (id :) becomes nil
- ruby - unable to save comments in db (rails)
- ruby - rails: fattachment_field gives undefined method error
- ruby on rails 5 - the path is changed by redirect_to of rails
- ruby - partial template is not displayed (rails)
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory