Skip to content

[avram] Create a new empty User model object as User.new in ActiveRecord. #1712

Answered by jwoertink
zw963 asked this question in Q&A
Discussion options

You must be logged in to vote

In Avram you can't have an empty model because this breaks the Lucky convention of type-safety first, and the representation that a model is just a read-only container of data. How you would do this would be to use a SaveOperation.

get "/users/new" do |env|
  operation = SaveUser.new
end

post "/users" do |env|
  # I'm not totally sure how to write params from Kemal
  params = Avram::Params.new(env.params)
  SaveUser.create(params) do |op, user|

  end
end

get "/users/:user_id/edit" do |env|
   user = UserQuery.find(user_id)
   operation = SaveUser.new(user)
end

patch "/users/:user_id" do |env|
  params = Avram::Params.new(env.params)
  user = UserQuery.find(user_id)
  SaveUser.update(u…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@zw963
Comment options

@jwoertink
Comment options

@zw963
Comment options

@jwoertink
Comment options

@zw963
Comment options

Answer selected by zw963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants