vendredi 19 février 2016

building user profile page rails

I am currently working on writing code to build a profile page for each user that signs into my application. However I have spent many hours and can't seem to figure this one out. Please excuse me for any lack of knowledge, I am rails beginner and still am learning.

Here is part of my User Model to build the initial profile page:

  has_one :profile

  after_create :build_profile

  def build_profile
    Profile.create(user: self)
  end

In my Profiles_controller.rb

before_action :find_profile, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]

def index
  @profile = Profile
end

def show
  @profile = Profile.find(profile_params)
end


def edit
  @profile = Profile.find(params[:id])
end

def update
  @profile = Profile.find(params[:id])
  @profile.update(profile_params)
end

private

def find_profile
  @profile = Profile.find(params[:id])
end

def profile_params
  params.permit(:profile).permit(:name, :summary, :birthday, :user_id)
end

Here is my edit.html.erb

 <%= simple_form_for @profile do |f| %>
  <%= f.input :name %>
  <%= f.date_select :birthday %>
  <%= f.text_field :summary %>
  <%= f.button :submit, 'Save', class: 'submit' %>
 <% end %>

When I navigate to profiles/28/edit, I receive the appropriate form. However upon saving the form my database does not update with the attributes I provided. Any direction, help or hints would be appreciated. If any further information is needed let me know. Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire