Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How is it done to pass default values in the controller?

Rails • Asked by Nicolás Bobb

Some values by default and others by strong parameters from the views

Generally, I put default values in the model itself rather than the controller.

class User
  after_initialize :set_defaults

    def set_defaults ||= "[email protected]"

I have access to current_user in model ?

I'm try:

def classroom_params
       params.require(:classroom).permit(:name, :owner_id => [current_user])

But don't work because "owner.required".

You don't have access to that in the model. For assigning current_user, I do that in the controller but all other defaults I'd put in the model.

def create
  @record =
    @record.owner = current_user

    #... etc

Thanks for all your help!! :)

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.