ruby on rails - What am I missing to get a profile page to include additional fields such as address, avatar, phone number -


i using ruby on rails , utilized devise log in , registration. after signing up, error message:

nomethoderror in devise::sessionscontroller#create undefined method profile_path' #<devise::sessionscontroller:0x007f9425b1f9c0> 

i used rails generate scaffold profile , have following code:

profiles_controller.rb

class profilescontroller < applicationcontroller   before_action :set_profile, only: [:show, :edit, :update, :destroy]   def profile    end   # /profiles   # /profiles.json   def index     @profiles = profile.all   end    # /profiles/1   # /profiles/1.json   def show   end    # /profiles/new   def new     @profile = profile.new   end    # /profiles/1/edit   def edit    @profile = profile.find_by user_id: current_user.id    @attributes = profile.attribute_names - %w(id user_id created_at updated_at)   end    # post /profiles   # post /profiles.json   def create     @profile = profile.new(profile_params)      respond_to |format|       if @profile.save         format.html { redirect_to @profile, notice: 'profile created.' }         format.json { render :show, status: :created, location: @profile }       else         format.html { render :new }         format.json { render json: @profile.errors, status: :unprocessable_entity }       end     end   end    # patch/put /profiles/1   # patch/put /profiles/1.json   def update     respond_to |format|       if @profile.update(profile_params)         format.html { redirect_to @profile, notice: 'profile updated.' }         format.json { render :show, status: :ok, location: @profile }       else         format.html { render :edit }         format.json { render json: @profile.errors, status: :unprocessable_entity }       end     end   end    # delete /profiles/1   # delete /profiles/1.json   def destroy     @profile.destroy     respond_to |format|       format.html { redirect_to profiles_url, notice: 'profile destroyed.' }       format.json { head :no_content }     end   end    private     # use callbacks share common setup or constraints between actions.     def set_profile       @profile = profile.find(params[:id])     end      # never trust parameters scary internet, allow white list through.     def profile_params       params[:profile]     end end 

application_controller.rb

class applicationcontroller < actioncontroller::base  # prevent csrf attacks raising exception.  # apis, may want use :null_session instead.  protect_from_forgery with: :exception  before_filter :configure_permitted_parameters, if: :devise_controller?  protected   def configure_permitted_parameters    devise_parameter_sanitizer.for(:sign_up) << :name    devise_parameter_sanitizer.for(:account_update) << :name  end    def after_sign_in_path_for(resource)     profile_path(resource)   end    def after_sign_up_path_for(resource)     profile_path(resource)   end end 

profile.rb

class profile < activerecord::base     belongs_to :user end 

user.rb

class user < activerecord::base   # include default devise modules. others available are:   # :confirmable, :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable     has_many :pins, dependent: :destroy      validates :name, presence: true has_one :profile     before_create :build_profile #creates profile @ user registration end 

routes.rb

rails.application.routes.draw   resources :profiles, only: [:edit]    resources :pins    devise_for :users   #devise_for :installs   root "pins#index"   "about" => "pages#about" 

thanks.

you need use plural: profiles_path rather profile_path, in application_controller.rb.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -