ruby on rails - ArgumentError in StaticPages#manager -


i have problem item creation. have next error:

argumenterror in staticpages#manager  showing /home/verevkinra/apps/yurta24/app/views/items/_new.html.erb line #2 raised:  first argument in form cannot contain nil or empty  extracted source (around line #2): <h1>items manage</h1> <%= form_for @item |f| %>    <%= f.text_field :variable1 %>    <%= f.text_field :variable2 %>    <%= f.text_field :variable3 %>    <%= f.text_field :variable4 %>  trace of template inclusion: app/views/static_pages/manager.html.erb  rails.root: /home/verevkinra/apps/yurta24 

first argument in form cannot contain nil or empty on second line of code (app/view/items/new.html.erb):

<h1>items manage</h1> <%= form_for @item |f| %>    <%= f.text_field :variable1 %>    <%= f.text_field :variable2 %>    <%= f.text_field :variable3 %>    <%= f.text_field :variable4 %>    <%= f.text_field :value1 %>    <%= f.text_field :value2 %>    <%= f.text_field :value3 %>    <%= f.text_field :value4 %>    <%= f.text_field :comment %>     <%= f.submit %> <% end %> 

my items_controller.rb is:

class itemscontroller < applicationcontroller        def new        @item = item.new     end     def create        @item = item.new item_params        @item.save     end      def destroy          @item = item.find(params[:id])          @item.destroy       end      private      def item_params        params.require(:item).permit(:variable1, :variable2, :variable3, :variable4, :value1, :value2, :value3, :value4, :comment)     end end 

my db migration file is:

class createitems < activerecord::migration   def change     create_table @item |t|       t.string :variable1       t.string :variable2       t.string :variable3       t.string :variable4       t.string :value1       t.string :value2       t.string :value3       t.string :value4       t.string :comment        t.timestamps null: false     end   end end 

my routes.rb has next line:

resources :items 

thanks

my static_pages_controller.rb is:

class staticpagescontroller < applicationcontroller   def home     @contact_form = contactform.new    end    def manager     @contact_messages = contactform.all     @item = item.new   end end 

line @item = item.new i've add right , there error:

nomethoderror in staticpages#manager  showing /home/verevkinra/apps/yurta24/app/views/items/_new.html.erb line #8 raised:  undefined method `value2' #<item:0xb3ba6504>  extracted source (around line #8):    <%= f.text_field :variable4 %>    <%= f.text_field :value1 %>    <%= f.text_field :value2 %>    <%= f.text_field :value3 %>    <%= f.text_field :value4 %>    <%= f.text_field :comment %>  trace of template inclusion: app/views/static_pages/manager.html.erb 

app/views/static_pages/manager.html.erb is:

<%= render 'contact_forms/new' %> <%= render 'items/new' %> 

first argument in form cannot contain nil or empty

you rendering partial(app/views/items/_new.html.erb) in app/views/static_pages/manager.html.erb, should having @item = item.new in manager method of static_pages_controller.rb

#static_pages_controller.rb def manager   @item = item.new end 

undefined method `value2' item:0xb3ba6504

that attribute value2 not find in items table. create migration below command

rails g migration add_value2_to_items value2:string

change create_table @item |t| create_table :items |t| in migration file , rake db:migrate


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -