I have a form with only one field called secretcode to submit. But when
I submit it, the data is saved. But I need to do form validation for
this field. I have given validates_presence_of :secret in the Secretcode
Model. when I submit it without entering anything in secret code field,
then it is showing as "undefined method `model_name' for
NilClass:Class".. Please help. I am learning rails by doing..

new.html.erb

> <%=form_for(@secretcode) do |f|%> <%= render 'layouts/error' %>
> <%=f.label :secret%> <%= f.text_field :secret %>
>
> <%=f.submit :generate%> <%end%>

Secretcode Model

> class Secretcode < ActiveRecord::Base   belongs_to :user
> attr_accessible :secret   validates(:secret, :presence=> true) end

secretcodes controller



> def create
>     @code= Secretcode.new(params[:secretcode])
>     if @code.save
>       p "It is saved..........."
>       redirect_to @code
>     else
>       render 'new'
>     end
>
>
>   end

-- 
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 https://groups.google.com/groups/opt_out.


Reply via email to