3

I have created a ToDoList based off Hartl's tutorial, and following a guide to add a tagging system. I have followed till Section 10, where they asked me to modify my new.html.erb file to the code as shown on the source.

<div class = 'col-md-8 offset-2'>
  <h1 class = "text-center">New Blog Post</h1>
  <%= simple_form_for @post, url: posts_path do |f| %>
    <%= f.input :title %>
    <%= f.input :content %>
    <%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: {multiple: true} %>
    <%= f.submit "Next", class: 'btn btn-lg btn-primary float-right' %>
  <% end %>
</div>

Since my ToDoList displays the tasks on the static_pages, I improvised and changed micropost_form.html.erb instead.

Before change:

<%= form_for(@micropost) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
    <%= f.text_area :content, placeholder: "Add new task..." %>
  </div>
  <%= f.submit "Add Task", class: "btn btn-primary" %>
<% end %>

After change:

<%= simple_form_for @micropost, url: microposts_path do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
    <%= f.text_area :content, placeholder: "Add new task..." %>
    <%= f.input :tag_ids, as: :select, collection: Tag.order(:name), label_method: :name, input_html: {multiple: true} %>
  </div>
  <%= f.submit "Add Task", class: "btn btn-primary" %>
<% end %>

This produced the error.

NoMethodError in StaticPages#home

undefined method `simple_form_for' for #<#<Class:0x00007f8d6c84d4f0>:0x00007f8d6c833230>
Did you mean?  simple_format

Can anyone suggest what might be wrong here? Please let me know if more information is needed.

Prashin Jeevaganth
  • 1,223
  • 1
  • 18
  • 42
  • Did you install the simple_form gem? The tutorial doesn't list it in the Boostrap Gemfile update, and instead hides it at the end of the section: "To install Simple Form, add to your Gemfile `gem ‘simple_form’`" – Tom Jan 20 '19 at 21:11
  • Yes, I realised that after I re-read the tutorial, now my code compiles but the text box isn't working for the tag_id side. – Prashin Jeevaganth Jan 21 '19 at 01:12

1 Answers1

1

The most common solution to resolve problem like this, is restart the server. You should always do this after install gem. Have you tried this?

barmic
  • 1,042
  • 7
  • 15
  • Yes, I have resolved this problem, thank you for the answer. I now have a new problem at https://stackoverflow.com/questions/54282979/actioncontroller-urlgenerationerror instead. Would you mind helping me out there? – Prashin Jeevaganth Jan 21 '19 at 11:06