Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method `simple_form_for'

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.

like image 994
Prashin Jeevaganth Avatar asked Apr 18 '26 00:04

Prashin Jeevaganth


1 Answers

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?

like image 179
barmic Avatar answered Apr 20 '26 15:04

barmic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!