0

I'm trying to add a Profile page for the users of my App.

I followed railscasts 250 & 274 to set up my user authentication & added the below to get a user profile.

users/show.html.erb

<div class="page-header">
  <h1><%= @user.name %> Profile</h1>
</div>

<p>
  <b>email:</b>
  <%= @user.email %>
</p>

layouts/_navbar.html.erb

<%= link_to "View your Profile", user_path(user) %>

users_controller.rb

  def show
    @user = User.find(params[:id])
  end

This throws back a undefined local variable or method 'user' error.

So I tried adding both of these lines to my application_controller.rb :

@user = User.all

&

@user = User.all.find(params[:id])

But these returned the following error respectively

undefined local variable or method `user'

&

undefined local variable or method `params'

I have resources :users in my routes.rb file & I've also tried adding get 'users/:id', :to => 'users#show', :as => 'user' without any success.

4

2 に答える 2

2

現在ログインしているユーザーの表示ページに移動するには:

<%= link_to "View your Profile", current_user %>

show アクションはそのままにして、ルートだけをresources :users

于 2013-04-08T09:51:35.477 に答える