samedi 20 août 2016

Ruby on Rails Simple Forms Error

I'm a Ruby and Ruby on Rails beginner, started 2 days ago. I'm trying to build a basic app for the first time and I get this error when I try to use simple_forms gem.

Before I show you the code I want to specify that if I delete the simple_forms code, it works, it redirects me to /orders/new page and it display the HTML page.

This is my error: NoMethodError in Orders#new Showing /home/ubuntu/workspace/app/views/orders/_form.html.erb where line #2 raised: undefined method `amazonurl' for #

My code:

routes.rb

Rails.application.routes.draw do

resources :orders

root 'orders#index'

end

orders_controller

class OrdersController < ApplicationController
    def index
    end

    def new
        @order = Order.new
    end

    def create
        @order = Order.new(order_params)
    end

    private
    def order_params
        params.require(:order).permit(:amazonurl, :dname, :daddress, :dphone)
    end
end

Migration

class CreateOrders < ActiveRecord::Migration
  def change
    create_table :orders do |t|

      t.string :amazonurl
      t.text :dname
      t.text :daddress
      t.text :dphone

      t.timestamps null: false
    end
  end
end

Form ( _form.html.erb)

<%= simple_form_for @order  do |f| %>
  <%= f.input :amazonurl %>
  <%= f.input :dname %>
  <%= f.input :daddress %>
  <%= f.input :dphone %>
  <%= f.button :submit %>
<% end %>

And my new.html.erb file

<h1>New Order</h1>
  <%= render 'form' %>

Thank you very much, I hope we figure it out!

Aucun commentaire:

Enregistrer un commentaire