Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# app/services/create_entry.rb
class CreateEntry
class NotValidEntryRecord < StandardError; end
def initialize(user, params)
@user = user
@params = params
end
def call
@entry = Entry.new(@params)
if @entry.valid?
entry = Entry.new(@params)
entry.user = @user
entry.status = EntryStatus.new(
@params[:status_weather],
@params[:status_landform]
)
entry.save!
else
raise(NotValidEntryRecord, @entry.errors.full_messages.to_sentence)
end
end
end

thauanz commented Dec 14, 2016

Hi @eqbal,

I think without you adding accessor for @entry, the controller EntriesController#create is not going access the variable when is not success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment