Ruby On Rails - NoMethodError -


hy guys... i'm learning ruby on rail don't know whats going on on page, error:

nomethoderror in contacts#new showing /home/ubuntu/workspace/simplecodecasts_saas/app/views/contacts/new.html.erb line #7 raised: undefined method `name' #

this new.html.erb

<div class="row">   <div class="col-md-4 col-md-offset-4">     <div class="well">       <%= form_for @contact |f| %>         <div class="form-group">           <%= f.label :name %>           <%= f.text_field :name, class: 'form-control' %>         </div>         <div class="form-group">           <%= f.label :email %>           <%= f.email_field :email, class: 'form-control' %>         </div>         <div class="form-group">           <%= f.label :comments %>           <%= f.text_area :comments, class: 'form-control' %>         </div>         <%= f.submit 'submit', class: 'btn btn-default' %>       <% end %>     </div>   </div> </div> 

this routes

rails.application.routes.draw   resources :contacts   '/about' => 'pages#about'   root 'pages#home' 

and contacts_controller.rb

class contactscontroller < applicationcontroller    def new     @contact = contact.new   end    def create   end  end 

what going wrong?

full error screen screen

it means contact record doesn't have name attribute, reason being don't have in db.

to fix it, run rake db:migrate... or if haven't created migration yet, should follow these steps:

$ rails g migration addattrstocontacts  #db/migrate/add_attrs_to_contacts____.rb class addattrstocontacts < activerecord::migration    def change        add_column :contacts, :name, :string        add_column :contacts, :email, :string        add_column :contacts, :comments, :text    end end  $ rake db:migrate 

this populate table appropriate columns, , should resolve error.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -