jesper
jesper

Reputation: 227

More functions in one controller /something/something

Currently when adding a controller it has ex. /dashboard/index How can i implementate /dashboard/editaccount ex? How can i "render" template for this (view)?

class DashboardController < ApplicationController
  def index
     u = Users.find(session[:id])
     @username = u[:username]
  end

  def editaccount
     ##Some code??
  end
end

I am completly new in ruby on rails, so hope you can answer me beginner question.

Upvotes: 0

Views: 40

Answers (1)

Thomas Klemm
Thomas Klemm

Reputation: 10856

class DashboardsController < ApplicationController
  def index
     user = Users.find(session[:id])
     @username = user[:username]
  end

  def edit_account
    # Your code
    # automatically renders the 'edit_account' template
  end
end

# config/routes.rb
resource :dashboard do
  get 'edit_account', on: :collection
end

Learn more on Routing in the Rails Guides.

Please be aware that I changed the naming of your DashboardController to DashboardsController. It's customary to name controllers in Rails in plural, even when using singular routes (see the Rails guides link above and search for singular resources).

Upvotes: 1

Related Questions