Formtasti c форма не подана - рельсы 6 - PullRequest
0 голосов
/ 04 апреля 2020

Я пытаюсь создать очень простую форму отправки внутри _form. html .erb файла. Однако форма не отправляется. Если я пытаюсь создать новое сообщение, после нажатия кнопки «Отправить», страница просто обновляется, и в базу данных ничего не сохраняется. Я использую Rails 6.0.2.1.

Это форма под _form. html .erb

<form>
  <%= semantic_form_for @post do |f| %>
    <div class="form-row">
      <%= f.inputs do %>
        <div class="form-group col-md-12">
          <%= f.input :title, :label => 'Title', :required => true, :wrapper_html => { :class => "important", :size => 10 } %>
        </div>
        <div class="form-group col-md-12">
          <%= f.input :body, :label => 'Post', :required => true, :input_html => { :class => 'autogrow', :rows => 10, :cols => 20, :maxlength => 500  } %>
        </div>
        <div class="form-group col-md-12">
          <%= f.input :section, :label => 'Tag', :as => :select, :collection => ["Finance", "Arts/Music", "Sports", "Mood", "Technology", "Health", "News", "Politics", "Literature", "Food", "Life", "Pet", "Shopping"] %>
        </div>
        <div class="form-group col-md-12">
          <%= f.input :location, :as => :country, :label => 'Where are you posting' %>
        </div>
        <div class="form-group col-md-12">
          <%= f.input :username %>
        </div>
      <% end %>
    </div>
    <%= f.actions do %>
      <%= f.action :submit, label: "Submit" %>
    <% end %>
  <% end %>
</form>

Часть posts_controller.rb

class PostsController < ApplicationController
  def new
    @post = Post.new
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  # POST /posts.json
  def create
    "puts creating post"
    @post = Post.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  def post_params
    params.require(:post).permit(:title, :body, :section, :location, :username)
  end
end

models / post.rb

class Post < ApplicationRecord
    attr_accessor :title, :body, :section, :location, :username
end
...