There are 2 tables, User and Post, and on the user’s page I’m trying to make form_for to enter a post and further output to the screen. my profile_controller.rb
def show @user = current_user @post = current_user.posts.build end Here is the post_controller.rb :
before_action :set_post, only: [:show, :edit, :update] respond_to :html, :js def index @post = Post.all end def show end def new @post = Post.new end def edit end def create @post = current_user.posts.new(post_params) respond_to do |format| if @post.save format.html { redirect_to @post, notice: 'Post was successfully created.' } format.js{} 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 update respond_to do |format| if @post.update!(post_params) format.html { redirect_to @post, notice: 'Post was successfully updated.' } format.json { render :show, status: :ok, location: @post } else format.html { render :edit } format.json { render json: @post.errors, status: :unprocessable_entity } end end end private def set_post @post = Post.find(params[:id]) end def post_params params.require(:post).permit(:comment,:user_id,:created_at) end routes.rb:
devise_for :users, controllers: {registrations: 'registrations'} root "welcome#index" # путь к profile/index get "/profile" => "profile#show", as: :profile And the actual form on which he swears, c variable @post show.html :
<%= form_for @post do |f| %> <div class="one"> <%= f.label :comment %><br /> <%= f.text_field :comment, autofocus: true%> </div> <div class="btn-link"><br /> <%= f.submit "Send" %> </div> There are suspicions that these are methods in post_controller that do not work properly and send me to post_path, but I don’t take what it is.