Created
January 29, 2019 11:33
-
-
Save elithecho/5cd9792248a92eacf539003f638fe077 to your computer and use it in GitHub Desktop.
Slim model with Form object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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