Active model error for forbidden attributes

can anyone help me understand this error. I am trying to create a contact form in rails, following the guide for creating web applications. I followed the steps to create an advertising scaffold. Then I corrected my routes. He then said to enable this in the message manager action.

if @message.save
  flash[:notice] = 'Thanks for Your Message'
  format.html { redirect_to root_path }

I did this and I get the following ActiveModel :: ForbiddenAttributesError error in MessagesController # create ActiveModel :: ForbiddenAttributesError

This is my message manager file

class MessagesController < InheritedResources::Base 
  def show
     if @message.save
      flash[:notice] = 'Thanks for Your Message'
      format.html { redirect_to root_path }
     end
  end
end

My routes file is as follows

# devise_for :users
Resources

: products resources: orders, only: [: new ,: create] #tells rails product identification number is required end

  # get 'pages/payment'

  get 'home/about'

  get 'messages/new'

  get 'seller' => "products#seller"

  get 'sales' => "orders#sales"

  get 'static_pages/productlanding'

  get "content/veg"

  get "content/fruit"

  get "content/mix"

  get 'subscriptions/new'

  root 'static_pages#home'
+4
3

!

class MessagesController < ApplicationController
  before_action :set_message, only: [:show, :edit, :update, :destroy]

  # GET /messages
  # GET /messages.json
  def index
    @messages = Message.all
  end

  # GET /messages/1
  # GET /messages/1.json
  def show
  end

  # GET /messages/new
  def new
    @message = Message.new
  end

  # GET /messages/1/edit
  def edit
  end

  # POST /messages
  # POST /messages.json
  def create
    @message = Message.new(message_params)

    respond_to do |format|
      if @message.save
        flash.now[:notice] = 'Thank you for your message!'
        format.html { redirect_to root_path }
        format.json { render :show, status: :created, location: @message }
      else
        format.html { render :new }
        format.json { render json: @message.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /messages/1
  # PATCH/PUT /messages/1.json
  def update
    respond_to do |format|
      if @message.update(message_params)
        format.html { redirect_to @message, notice: 'Message was successfully updated.' }
        format.json { render :show, status: :ok, location: @message }
      else
        format.html { render :edit }
        format.json { render json: @message.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /messages/1
  # DELETE /messages/1.json
  def destroy
    @message.destroy
    respond_to do |format|
      format.html { redirect_to messages_url, notice: 'Message was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_message
      @message = Message.find(params[:id])
    end

    .
    def message_params
      params.require(:message).permit(:name, :email, :company, :phone, :subject, :body)
    end
end
+1

show?

-

Params

ForbiddenAttributes strong_params Rails.

strong_params. :

#app/controllers/messages_controller.rb
class MessagesController < ApplicationController
   def show
      @message = Message.find(params[:id])
   end

   def new
      @message = Message.new
   end

   def create
      @message = Message.new(message_params)
      @message.save
   end

   private

   def message_params
      params.require(:message).permit(:your, :message, :params)
   end
end

controller . -, ( @save, -).

+12

. "" , .

:

def create
  if @message.save
   flash[:notice] = 'Thanks for Your Message'
   format.html { redirect_to root_path }
  end
end
+1
source

All Articles