Daniel W
Daniel W

Reputation: 73

Avoid slugging Certain Views with Friendly_ID

When using friendly_id, views that don't necessarily need to show the user's screen name are being displayed. For example. 127.0.0.1:3000/users/info.todacken333 How can I avoid showing the username on views like settings or edit current_user.account, etc??

route.rb

get '/users/info', to: 'users#info'

Upvotes: 0

Views: 25

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

You'll be best looking at singular resources:

#config/routes.rb
resource :users, only: :edit, path_names: { edit: "info" } #-> url.com/user/info

#app/controllers/users_controller.rb
class UsersController < ApplicationController
  def edit
    # Use current_user in view
  end
end

#view
<%= link_to "Info", edit_user_path %>

The problem you have is that you're passing your current_user to your path helper (probably because it requires it). Using singular resources (above) will remove the need for that.

Upvotes: 1

Related Questions