On Jun 26, 2012, at 5:45 PM, cyber c. wrote:

> 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

Then I would try writing just one validation, and see if you can make that 
work. And by the way, look, that colon at the end of validates has crept back 
in there. Is that a paste from your model, or your previous e-mail?

Try using 

validates_presence_of :ipaddress

and see what happens.

I've never tried using ActiveModel before, so I'm guessing here.

Walter

> 
> -- 
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to