# Application template recipe for the rails3_devise_wizard. Check for a newer version here: # https://github.com/fortuity/rails3_devise_wizard/blob/master/recipes/users_page.rb after_bundler do say_wizard "UsersPage recipe running 'after bundler'" #---------------------------------------------------------------------------- # Create a users controller #---------------------------------------------------------------------------- generate(:controller, "users show") gsub_file 'app/controllers/users_controller.rb', /def show/ do <<-RUBY before_filter :authenticate_user! def show @user = User.find(params[:id]) RUBY end #---------------------------------------------------------------------------- # Modify the routes #---------------------------------------------------------------------------- # @devise_for :users@ route must be placed above @resources :users, :only => :show@. gsub_file 'config/routes.rb', /get \"users\/show\"/, '#get \"users\/show\"' gsub_file 'config/routes.rb', /devise_for :users/ do <<-RUBY devise_for :users resources :users, :only => :show RUBY end #---------------------------------------------------------------------------- # Create a users show page #---------------------------------------------------------------------------- if recipes.include? 'haml' remove_file 'app/views/users/show.html.haml' # There is Haml code in this script. Changing the indentation is perilous between HAMLs. # We have to use single-quote-style-heredoc to avoid interpolation. create_file 'app/views/users/show.html.haml' do <<-'HAML' %p User: #{@user.name} HAML end else append_file 'app/views/users/show.html.erb' do <<-ERB

User: <%= @user.name %>

ERB end end #---------------------------------------------------------------------------- # Create a home page containing links to user show pages # (clobbers code from the home_page_users recipe) #---------------------------------------------------------------------------- # set up the controller remove_file 'app/controllers/home_controller.rb' create_file 'app/controllers/home_controller.rb' do <<-RUBY class HomeController < ApplicationController def index @users = User.all end end RUBY end # modify the home page if recipes.include? 'haml' remove_file 'app/views/home/index.html.haml' # There is Haml code in this script. Changing the indentation is perilous between HAMLs. # We have to use single-quote-style-heredoc to avoid interpolation. create_file 'app/views/home/index.html.haml' do <<-'HAML' %h3 Home - @users.each do |user| %p User: #{link_to user.name, user} HAML end else remove_file 'app/views/home/index.html.erb' create_file 'app/views/home/index.html.erb' do <<-ERB

Home

<% @users.each do |user| %>

User: <%=link_to user.name, user %>

<% end %> ERB end end end __END__ name: UsersPage description: "Add a users controller and user show page with links from the home page." author: fortuity requires: [devise] category: other tags: [utilities, configuration]