Home>
I want to tag event posts
Please write your question in detail here.
I am making an application that can post the contents of the event etc. with ruby. I tried to save event information and tag information at the same time using a form object to implement the tagging function, but I got an error that the tag column was not defined. I think that there are some parts that are difficult to understand in the first post, but thank you.
[email protected] ■■ The following error message occurred while implementing the function.
### Error message

ruby

undefined method `tag_name'for #<Event: 0x00007f9598d364b0>
Extracted source (around line # 23):

  def save
    event = Event.create (name: name, explanation: explanation, facility_id: facility_id, scale_id: scale_id, category_id: category_id, volunteer: volunteer, user_id: user_id)
    tag = Tag.where (tag_name: tag_name) .first_or_initialize
    tag.save
Corresponding source code

event_model

class Event</pre>
<p><br />
events_controller.rd</p>
<pre><code data-language = "Ruby">class EventsController</pre>
<p>events_tag.rb</p>
<pre><code>`` `ruby
class EventsTag
include ActiveModel :: Model
attr_accessor: name,: expansion,: facility_id,: scale_id,: category_id,: volunteer,: tag_name,: user_id

with_options presence: true do
validates: name
validates: expansion
validates: facility_id
validates: scale_id
validates: category_id
validates: tag_name
end
with_options numericality: {other_than: 1} do
validates: facility_id
validates: scale_id
validates: category_id
end

def save
event = Event.create (name: name, explanation: explanation, facility_id: facility_id, scale_id: scale_id, category_id: category_id, volunteer: volunteer, user_id: user_id)
tag = Tag.where (tag_name: tag_name) .first_or_initialize
tag.save
EventTagRelation.create (event_id: event.id, tag_id: tag.id)
end
end

_form.html.erb


<% = f.label: tag_name, "tag"%>
<% = f.text_field: tag_name, class: "input-tag"%>

`` ```

What I tried

I checked params in binding.pry, but the data of tag_name was created.
I searched for error information about form objects, but couldn't find it.
Please describe here what you have tried for the problem.

Supplementary information (FW/tool version, etc.)

ruby '2.6.5'
Please provide more detailed information here.