Skip to content

Instantly share code, notes, and snippets.

@elithecho
Created January 29, 2019 11:33
Show Gist options
  • Save elithecho/5cd9792248a92eacf539003f638fe077 to your computer and use it in GitHub Desktop.
Save elithecho/5cd9792248a92eacf539003f638fe077 to your computer and use it in GitHub Desktop.
Slim model with Form object
class ProfilesController < ApplicationController
def new
@form = ProfileForm.new(current_user)
end
def create
@form = ProfileForm.new(current_user, form_params)
# Now your form can act like a model
if @form.save
flash[:success] = "This is successful"
redirect_to :success
else
flash[:error] = "Please look into the errors"
render :new
end
end
private
def form_params
params.require(:profile_form).permit(
user_attributes: [:name, :attributes_to_update],
profile_attributes: [:country, :bio, :more_attributes_to_update]
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment