Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Last active December 10, 2015 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adammcarth/4352511 to your computer and use it in GitHub Desktop.
Save adammcarth/4352511 to your computer and use it in GitHub Desktop.
NoMethodError - Ruby on Rails
<!-- Someone can visit http://localhost:3000/profiles/my-permalink and this page will display (this part is working fine!). -->
<h2>Edit your profile, <%= @user.first_name %>.</h2>
<%= form_for @user, :html => { :class => "form-horizontal"} do |f| %>
<%= f.label :first_name, "Your First Name" %>
<%= f.text_field :first_name %>
<%= f.submit "Update Profile" %>
<% end %>
# My profiles Model
class Profile < ActiveRecord::Base
belongs_to :user
end
class ProfilesController < ApplicationController
def index
@profile = Profile.find_by_permalink params[:id]
end
def show
@profile = Profile.find_by_permalink params[:id]
@user = @profile.user
end
def edit
@profile = Profile.find_by_permalink params[:id]
@user = @profile.user
end
def update
@profile = Profile.find_by_permalink params[:id]
@user = @profile.user
if @user.update_attributes(params[:user])
redirect_to profiles_path, :notice => "Your account was successfully updated!"
else
render "new"
end
end
def destroy
end
end
# My users model
class User < ActiveRecord::Base
acts_as_authentic
has_one :profile
after_create :create_the_profile
def create_the_profile
Profile.create(:user_id => id, :permalink => "2253" + id.to_s)
end
end
# This is my UsersController, which acts as my user platform for my application. It is there simply to store/hold the users information, and the model acts as the authentication system (AuthLogic). You are not meant to be able to access anything from the /users/ directory - it's simply a gateway!
class UsersController < ApplicationController
def index
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
flash[:success] = "Registration successful!"
redirect_to profiles_path
else
render :action => "new"
end
end
def edit
@user = current_user
end
def update
@profile = Profile.find_by_permalink params[:id]
@user = @profile.user
if @user.update_attributes(params[:user])
flash[:success] = "The user has been updated!"
redirect_to profiles_path
else
render :action => "edit"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment