Major form validation/submitting problem

Hello,

I create a form with simple_form. Now I got 2 problems:
1)The validation fails, fx when a field is filled, the validation says
the field is empty and the field is not marked red.

Here is the controller:

def new
@action = Action.new
@note_type =
[[‘Ad’,‘Ad’],[‘Promotion’,‘Promotion’],[‘Poll’,‘Poll’],[‘Location’,‘Location’]]
end

def create
@note_type =
[[‘Ad’,‘Ad’],[‘Promotion’,‘Promotion’],[‘Poll’,‘Poll’],[‘Location’,‘Location’]]
@action = Action.new(params[:action_params])
if @action.save
flash[:success] = “New Action saved”
redirect_to “/”
else
render ‘new’
end

end

private

def action_params
params.require(:action).permit(:action_name,
:startDate,:endDate,:contentURL,
:previewImageURL,:message,:noteType,
:prob,:maxSendingsDayAll,:maxSendingsTotalAll,
:maxSendingsDeviceAll,:maxSendingsDeviceTotal,
:updateInterval)
end

action.rb(model):
class Action < ActiveRecord::Base

VALID_URL_REGEX = /\A[\w+-.][email protected][a-z\d-.]+.[a-z]+\z/i
before_save { self.contentURL = contentURL.downcase }
before_save { self.previewImageURL = previewImageURL.downcase }

validates :action_name, presence: true

validates :startDate, presence: true

validates :endDate, presence: true

validates :contentURL, presence: true,
format: { with: VALID_URL_REGEX }

validates :previewImageURL, presence: true,
format: { with: VALID_URL_REGEX }

validates :message, presence: true

validates :noteType, presence: true

validates :prob, presence: true

validates :maxSendingsDayAll, presence: true

validates :maxSendingsTotalAll, presence: true

validates :maxSendingsDeviceAll, presence: true

validates :maxSendingsDeviceTotal, presence: true

validates :updateInterval, presence: true

end

new.html.erb

New Action

<%= simple_form_for(@action) do |f|%> <%= render 'shared/error_messages' %>
<%=f.label :action_name, "Action name"%>
<%=f.text_field :action_name%></br>

<%=f.input :startDate,:as => :datetime_picker, :label =>"Start

date"%>
<%=f.input :endDate,:as => :datetime_picker, :label =>“End date”%>

<%=f.label :contentURL, "Content url"%>
<%=f.text_field :contentURL%></br>

<%=f.label :previewImageURL, "Preview image url"%>
<%=f.text_field :previewImageURL%></br>

<%=f.label :message, "Message"%>
<%=f.text_area :message%></br>

<%=f.label :noteType, "Note type"%>
<%=f.select(:noteType, @note_type,:html =>("multiple"))%></br></br>


<%=f.label :prob, "Sending probhability"%>
<%=f.number_field :prob%></br>

<%=f.label :maxSendingsDayAll, "Maximum sendings per day"%>
<%=f.number_field :maxSendingsDayAll%></br>

<%=f.label :maxSendingsTotalAll, "Maximum sendings"%>
<%=f.number_field :maxSendingsTotalAll%></br>

<%=f.label :maxSendingsDeviceAll, "Maximum sendings per device"%>
<%=f.number_field :maxSendingsDeviceAll%></br>

<%=f.label :maxSendingsDeviceTotal, "Maximum sendings per device per

day"%>
<%=f.number_field :maxSendingsDeviceTotal%>

<%=f.label :updateInterval, "Action resend interval"%>
<%=f.number_field :updateInterval%></br>


<%= f.submit "Create Action", class: "btn btn-large btn-primary" %>

<%end%>

I know it is not good style to post so much code and asking for a
perfect solution. But I worked several days on this problem, and don’t
know how to solve it :frowning: Thanks for your help

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs