Ruby on Rails Saturday, June 30, 2012

when i try  /contact_mail/newi it return me error: undefined local variable or method `em' for #<#<Class:0x007fca24248858>:0x007fca21186df0>





model: contact_mail.rg
class ContactMail < ActiveRecord::Base
  attr_accessible :email, :message, :name, :subject

end

controler: contarct_mail_controller.rb
class ContactMailController < ApplicationController
 def new 
    @em=ContactMail.new
  end
  
  def create
    @em = ContactMail.new(params[:contact_mail])
    @em.save
  end
    
end


view: new.html.erb
<%= form_for(@em) do |f| %>
<div class="field">
<%= f.label :email %>
<%= f.text_field :email%><br />
<br />
</div>
<div class="actions">
<%= f.submit "wyslij" %><br />
</div>
<% end %>



when i add @em.save to def new in controller it pass but i't not the way i want to do it.
Do enyone know how can i fix it? or what is wrong with my solution? 

i had made 4 model and controllers allrady using this method and it works perfetly. 

i had add resources :contact_mail to routes. 




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/BH5lDzwUeEAJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.

No comments:

Post a Comment