tedconf / front_end_builds

Rails engine to manage front end builds and deployments
MIT License
75 stars 21 forks source link

Use build ids for build links #53

Closed samselikoff closed 9 years ago

samselikoff commented 9 years ago

Stupid 3.2, hacked together a solution but it's not very clean. Asked a question here: http://stackoverflow.com/questions/28237343/rails-3-update-attributes-not-working-for-related-model-id.

My solution was

def update
  if use_params(:app_update_params)[:live_build_id]
    new_build_id = use_params(:app_update_params)[:live_build_id]
    build = FrontEndBuilds::Build.find new_build_id
    @app.live_build = build
  end

  if @app.update_attributes( use_params(:app_update_params) )

    respond_with_json(
      { app: @app.serialize },
      location: nil
    )
  else
    respond_with_json(
      { errors: @app.errors },
      status: :unprocessable_entity
    )
  end
end

but I want something cleaner, if possible.