In a model say Task, I have following validation
validates_presence_of :subject, :project, :user, :status
How do I render error messages for these validations using some other controller.
Inside CustomController I am using,
Task.create(hash)
passing nil values in hash gives following error,
ActiveRecord::RecordInvalid in CustomController#create
Validation failed: Subject can't be blank
Code in the controller's create action
@task = Task.create(hash)
if @task.valid?
flash[:notice] = l(:notice_successful_update)
else
flash[:error] = "<ul>" + @task.errors.full_messages.map{|o| "<li>" + o + "</li>" }.join("") + "</ul>"
end
redirect_to :back
How to render error messages to user.
Task model is already built and it renders proper messages. i want to use its functionalities from a plugin.