Nick Noble


1,380 Experience
13 Lessons Completed
0 Questions Solved


Posted in Create a User Profile after saving a Devise User


how would you create an edit page with a form to edit the user profile

Assuming you are using devise and your models look something like this:

class Profile < ApplicationRecord
  belongs_to :user

# and 

class User < ApplicationRecord
  has_one :profile, dependent: :destroy
  after_create :init_profile

  def init_profile

Then in your profiles_controller.rb:

  def edit
      @profile = current_user.profile

  def update
      @profile = current_user.profile
    respond_to do |format|
      if @profile.update profile_params
        format.html { redirect_to edit_profile_path, notice: "Profile updated!" }
        format.json { render :edit, status: :ok, location: @profile }
        format.html { redirect_to edit_profile_path, flash: { error: "Profile could not be updated!" } }
        format.json { render json: @profile.errors.messages, status: :unprocessable_entity }

then in views/profiles/edit.erb:

<%= form_for @profile, url: {action: "update"} do |f| %>

  <!-- Whatever your fields are -->
  <%= f.text_field :name %>
  <%= f.text_area :bio %>

  <%= f.submit "Update Profile" %>
<% end %>

Using @profile = current_user.profile instead of @profile = Profile.find(params[:id]) means that you always get the currently logged in user's profile when they go to an edit view, so they can't get anyone else's. It also sets up the form to already know which user's profile to update. If anyone has a reason not to do this, let me know!

When can we actually remove paperclip?

When I run the migration (with the provided code) I get:

ArgumentError: wrong number of arguments (given 1, expected 2..3)
/Users/nicknoble/products/Lnky/db/migrate/20180531013954_convert_to_active_storage.rb:14:in prepare'

Posted in Rails & Vue.js Trello Clone - Part 3 Discussion

Sorting the other way, i.e. `->{ order( position: :desc ) }` causes objects to get the wrong position on page refresh. Is there other configuration that needs to happen to make it set that properly on drag?

Posted in Create a User Profile after saving a Devise User

This is awesome, but is there a way to do it, get a and still be able to do something like this later:

# profile.rb
validates_presence_of :name, :bio

Posted in Inviting Users with devise_invitable Discussion

I figured it out (not perfect, but it works):

@owner = @project.project_users.where( role: "owner" ).first.user

Posted in Comments With Polymorphic Associations Discussion

How would you need to modify this to work with deeply nested resources?


resources :projects do
resources :project_users, path: :users, module: :projects
resources :posts do
resources :comments, module: :posts

Posted in Inviting Users with devise_invitable Discussion

How do you actually check that role field later, i.e. vs `current_user`?