Skip to content

Instantly share code, notes, and snippets.

@eqbal
Last active October 22, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eqbal/53985d930282ccede16f68aec99016cb to your computer and use it in GitHub Desktop.
Save eqbal/53985d930282ccede16f68aec99016cb to your computer and use it in GitHub Desktop.
# 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
Copy link

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