Skip to content

Instantly share code, notes, and snippets.

@Yorkshireman
Created February 1, 2016 00:46
Show Gist options
  • Save Yorkshireman/5aa2ad5971e4210cd1bd to your computer and use it in GitHub Desktop.
Save Yorkshireman/5aa2ad5971e4210cd1bd to your computer and use it in GitHub Desktop.
PadrinoBlog users controller pre-refactor
PadrinoBlog::App.controllers :users do
get :new do
@user = User.new
render 'users/new'
end
post :create do
user = User.new(params[:user])
if user.save
redirect('/sessions/new', notice: "Signed up successfully! Please Log in")
elsif (params[:user][:password_confirmation] != "") && (params[:user][:password] != params[:user][:password_confirmation])
redirect('/users/new', notice: "Password and Password Confirmation do not match. Please try again.")
else
redirect('/users/new', notice: "Please make sure you fill in all fields.")
end
end
end
@Yorkshireman
Copy link
Author

For example:

PadrinoBlog::App.controllers :users do

  get :new do
    say_hello
  end

  def say_hello
    puts "hello"
  end
end

This won't work.

How do I refactor stuff out into methods? I can create external helper modules with methods inside them, and then include that module here and call its methods, but I'd rather not do that.

I'm thinking along the lines of Rails controllers, how you just refactor stuff out into private methods in the controller class. I want to do something similar here, but obviously I can't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment