Hi,

I'm using rails 3.2.4.

I had referred to the activemodel episode from the rail casts and yes i 
included the initialize and persisted methods as specified. Still i dont 
see errors when i click the submit button with empty values

model
class Record
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming
  attr_accessor :ipaddress, :name
  validates: :ipaddress, :name, :presence => true
  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    return false
  end
end

View

    <%= form_for :Record  do |f| %>
      <%= f.error_messages %>
      <div class="field">
        <%= f.label :ipaddress %><br />
        <%= f.text_field :ipaddress  %>
      </div>
      <div class="field">
        <%= f.label :name %><br />
        <%= f.text_field :name  %>
      </div>
      <div class="actions">
        <%= f.submit "Submit"%>
      </div>
    <% end %>

Controller

def new
  @record = Record.new
end

def create
  @record = Record.new(params[:record])
  respond_to do |format|
     if @record.valid?
       DEPENDING on params this gets routed to different page
     else
       format.html { redirect_to records_url}
       format.json { head :no_content }
    end
  end

end

I dont see any errors but i see a refreshed page of records_url

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to