Forum: Ruby on Rails active record validations by Eshwar

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A3397c28170891359f35334ad05d09ee?d=identicon&s=25 cool (Guest)
on 2008-10-15 09:28
(Received via mailing list)
hi

 here is my form fields

          <tr>
                <td><%= text_field  :title, :name =>
'external_link[title][]' %></td>
                <td><%= text_field  :url, :name => 'external_link[url]
[]' %></td>
      </tr>
      <tr>
                <td><%= link_to_function 'Add', "add();" %></td>

if i click add link there will be added 2 more text fields as above

in the controller iam using like

 def create
    puts params[:external_link][:title].inspect
      params[:external_link][:title].each_with_index do |l, i|
  ExternalLink.create!({:title => l, :url => params[:external_link]
[:url][i], :label => params[:label]})
      end
      redirect url(:external_links)
  end

in the model i have specified as

validates_presence_of :title, :url


the problem is when i submit the the form with out entering any
details its not checking validation
its giving error like

Validation failed: Title can't be blank, Url can't be blank


how can i do that in the controller and model

badly i need a help in this its urgent and imp.....
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-15 10:13
(Received via mailing list)
On Oct 15, 8:28 am, cool <eshward...@gmail.com> wrote:
g like
> in the model i have specified as
>
> validates_presence_of :title, :url
>
> the problem is when i submit the the form with out entering any
> details its not checking validation
> its giving error like
>
> Validation failed: Title can't be blank, Url can't be blank

If you use the ! variants of save, create, update_attributes etc...
then validation failures raise an error instead of returning false.

Fred
A3397c28170891359f35334ad05d09ee?d=identicon&s=25 cool (Guest)
on 2008-10-15 10:58
(Received via mailing list)
then what can i use in the controller create method,
can u help me regarding this  plzz

On Oct 15, 1:13 pm, Frederick Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.