0

public_activityRailsアプリへの追加の進行が遅いです。

それは機能していますが、見栄えを良くするために正しいメソッドとリンクを呼び出すのに問題があります

私の activities.index.html がちょうど

<% @activities.each do |activity| %>
    <%= activity.inspect %>
<% end %>

私の見解では、私は見ることができます

#<PublicActivity::ORM::ActiveRecord::Activity id: 2, trackable_id: 41, trackable_type: "Guideline", owner_id: 12, owner_type: "User", key: "guideline.create", parameters: {}, recipient_id: nil, recipient_type: nil, created_at: "2013-03-07 08:25:45", updated_at: "2013-03-07 08:25:45"> #<PublicActivity::ORM::ActiveRecord::Activity id: 1, trackable_id: 40, trackable_type: "Guideline", owner_id: nil, owner_type: nil, key: "guideline.create", parameters: {}, recipient_id: nil, recipient_type: nil, created_at: "2013-03-07 08:21:09", updated_at: "2013-03-07 08:21:09">

私のactivities/index.html見解があるとき

<% @activities.each do |activity| %>
    <div class="activity">
    <%= link_to activity.owner.profile_name, activity.owner if activity.owner %>
    added guideline to <%= link_to activity.trackable.guideline.title, activity.trackable.guideline %>
</div>
<% end %>

エラーは

undefined method `user_path'

これは私のルートと関係がありますか? routes.rb

    Guidelines::Application.routes.draw do

  get "activities/index"

  # get "user/index"

  ActiveAdmin.routes(self)

  devise_for :admin_user, ActiveAdmin::Devise.config


  get "guidelines/topic"
  get "guidelines/topichospital"
  get "guidelines/topicspecialty"
  get "guidelines/favourite"
  get "profiles/show"
  get "guidelines/show"


  devise_for :users

  devise_scope :user do
    get 'signup', to: 'devise/registrations#new', as: :register
    get 'login', to: 'devise/sessions#new', as: :login
    get 'logout', to: 'devise/sessions#destroy', as: :logout
    get 'edit', to: 'devise/registrations#edit', as: :edit
    put 'users' => 'devise/registrations#update', :as => 'user_registration'
    get 'about', to: 'about#about', as: :about
  end

  resources :guidelines
  get 'guidelines', to: 'guidelines#index', as: :guidelines
  get 'favourites', to: "favourites#show", as: :favourites
  get 'topics', to: 'guidelines#list', as: :topics
  get 'hospitals', to: 'guidelines#listhospital', as: :hospitals
  get 'specialties', to: 'guidelines#listspecialty', as: :specialties


 resources :activities

  root :to => 'guidelines#index'

end

rake routes を実行すると、

activities_index GET        /activities/index(.:format)                           activities#index
                    admin_root            /admin(.:format)                                      admin/dashboard#index
batch_action_admin_admin_users POST       /admin/admin_users/batch_action(.:format)             admin/admin_users#batch_action
             admin_admin_users GET        /admin/admin_users(.:format)                          admin/admin_users#index
                               POST       /admin/admin_users(.:format)                          admin/admin_users#create
          new_admin_admin_user GET        /admin/admin_users/new(.:format)                      admin/admin_users#new
         edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)                 admin/admin_users#edit
              admin_admin_user GET        /admin/admin_users/:id(.:format)                      admin/admin_users#show
                               PUT        /admin/admin_users/:id(.:format)                      admin/admin_users#update
                               DELETE     /admin/admin_users/:id(.:format)                      admin/admin_users#destroy
               admin_dashboard            /admin/dashboard(.:format)                            admin/dashboard#index
 batch_action_admin_guidelines POST       /admin/guidelines/batch_action(.:format)              admin/guidelines#batch_action
              admin_guidelines GET        /admin/guidelines(.:format)                           admin/guidelines#index
                               POST       /admin/guidelines(.:format)                           admin/guidelines#create
           new_admin_guideline GET        /admin/guidelines/new(.:format)                       admin/guidelines#new
          edit_admin_guideline GET        /admin/guidelines/:id/edit(.:format)                  admin/guidelines#edit
               admin_guideline GET        /admin/guidelines/:id(.:format)                       admin/guidelines#show
                               PUT        /admin/guidelines/:id(.:format)                       admin/guidelines#update
                               DELETE     /admin/guidelines/:id(.:format)                       admin/guidelines#destroy
      batch_action_admin_users POST       /admin/users/batch_action(.:format)                   admin/users#batch_action
                   admin_users GET        /admin/users(.:format)                                admin/users#index
                               POST       /admin/users(.:format)                                admin/users#create
                new_admin_user GET        /admin/users/new(.:format)                            admin/users#new
               edit_admin_user GET        /admin/users/:id/edit(.:format)                       admin/users#edit
                    admin_user GET        /admin/users/:id(.:format)                            admin/users#show
                               PUT        /admin/users/:id(.:format)                            admin/users#update
                               DELETE     /admin/users/:id(.:format)                            admin/users#destroy
   batch_action_admin_comments POST       /admin/comments/batch_action(.:format)                admin/comments#batch_action
                admin_comments GET        /admin/comments(.:format)                             admin/comments#index
                               POST       /admin/comments(.:format)                             admin/comments#create
                 admin_comment GET        /admin/comments/:id(.:format)                         admin/comments#show
        new_admin_user_session GET        /admin/login(.:format)                                active_admin/devise/sessions#new
            admin_user_session POST       /admin/login(.:format)                                active_admin/devise/sessions#create
    destroy_admin_user_session DELETE|GET /admin/logout(.:format)                               active_admin/devise/sessions#destroy
           admin_user_password POST       /admin/password(.:format)                             active_admin/devise/passwords#create
       new_admin_user_password GET        /admin/password/new(.:format)                         active_admin/devise/passwords#new
      edit_admin_user_password GET        /admin/password/edit(.:format)                        active_admin/devise/passwords#edit
                               PUT        /admin/password(.:format)                             active_admin/devise/passwords#update
              guidelines_topic GET        /guidelines/topic(.:format)                           guidelines#topic
      guidelines_topichospital GET        /guidelines/topichospital(.:format)                   guidelines#topichospital
     guidelines_topicspecialty GET        /guidelines/topicspecialty(.:format)                  guidelines#topicspecialty
          guidelines_favourite GET        /guidelines/favourite(.:format)                       guidelines#favourite
                 profiles_show GET        /profiles/show(.:format)                              profiles#show
               guidelines_show GET        /guidelines/show(.:format)                            guidelines#show
              new_user_session GET        /users/sign_in(.:format)                              devise/sessions#new
                  user_session POST       /users/sign_in(.:format)                              devise/sessions#create
          destroy_user_session DELETE     /users/sign_out(.:format)                             devise/sessions#destroy
                 user_password POST       /users/password(.:format)                             devise/passwords#create
             new_user_password GET        /users/password/new(.:format)                         devise/passwords#new
            edit_user_password GET        /users/password/edit(.:format)                        devise/passwords#edit
                               PUT        /users/password(.:format)                             devise/passwords#update
      cancel_user_registration GET        /users/cancel(.:format)                               devise/registrations#cancel
             user_registration POST       /users(.:format)                                      devise/registrations#create
         new_user_registration GET        /users/sign_up(.:format)                              devise/registrations#new
        edit_user_registration GET        /users/edit(.:format)                                 devise/registrations#edit
                               PUT        /users(.:format)                                      devise/registrations#update
                               DELETE     /users(.:format)                                      devise/registrations#destroy
                      register GET        /signup(.:format)                                     devise/registrations#new
                         login GET        /login(.:format)                                      devise/sessions#new
                        logout GET        /logout(.:format)                                     devise/sessions#destroy
                          edit GET        /edit(.:format)                                       devise/registrations#edit
             user_registration PUT        /users(.:format)                                      devise/registrations#update
                         about GET        /about(.:format)                                      about#about
                    guidelines GET        /guidelines(.:format)                                 guidelines#index
                               POST       /guidelines(.:format)                                 guidelines#create
                 new_guideline GET        /guidelines/new(.:format)                             guidelines#new
                edit_guideline GET        /guidelines/:id/edit(.:format)                        guidelines#edit
                     guideline GET        /guidelines/:id(.:format)                             guidelines#show
                               PUT        /guidelines/:id(.:format)                             guidelines#update
                               DELETE     /guidelines/:id(.:format)                             guidelines#destroy
                    guidelines GET        /guidelines(.:format)                                 guidelines#index
                    favourites GET        /favourites(.:format)                                 favourites#show
                        topics GET        /topics(.:format)                                     guidelines#list
                     hospitals GET        /hospitals(.:format)                                  guidelines#listhospital
                   specialties GET        /specialties(.:format)                                guidelines#listspecialty
                    activities GET        /activities(.:format)                                 activities#index
                               POST       /activities(.:format)                                 activities#create
                  new_activity GET        /activities/new(.:format)                             activities#new
                 edit_activity GET        /activities/:id/edit(.:format)                        activities#edit
                      activity GET        /activities/:id(.:format)                             activities#show
                               PUT        /activities/:id(.:format)                             activities#update
                               DELETE     /activities/:id(.:format)                             activities#destroy
                          root            /                                                     guidelines#index
            guideline_comments GET        /guidelines/:guideline_id/comments(.:format)          comments#index
                               POST       /guidelines/:guideline_id/comments(.:format)          comments#create
         new_guideline_comment GET        /guidelines/:guideline_id/comments/new(.:format)      comments#new
        edit_guideline_comment GET        /guidelines/:guideline_id/comments/:id/edit(.:format) comments#edit
             guideline_comment GET        /guidelines/:guideline_id/comments/:id(.:format)      comments#show
                               PUT        /guidelines/:guideline_id/comments/:id(.:format)      comments#update
                               DELETE     /guidelines/:guideline_id/comments/:id(.:format)      comments#destroy
                               GET        /guidelines(.:format)                                 guidelines#index
                               POST       /guidelines(.:format)                                 guidelines#create
                               GET        /guidelines/new(.:format)                             guidelines#new
                               GET        /guidelines/:id/edit(.:format)                        guidelines#edit
                               GET        /guidelines/:id(.:format)                             guidelines#show
                               PUT        /guidelines/:id(.:format)                             guidelines#update
                               DELETE     /guidelines/:id(.:format)                             guidelines#destroy
4

2 に答える 2

1

user_pathルートファイルにユーザーshowビューのルートが含まれていないため、未定義のメソッドを取得しています。これを機能させるには、作成する必要があります。まず、users_controllerを作成し、その中でshowメソッドを定義する必要があります。

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

次に、routes.rbファイルでルートを作成します。

match '/users/:id', :to => 'users#show', :as => :user

:asパラメーターは、ルーターにルートの名前を指定します(:asパラメーターが何であれ、_pathまたは_urlを追加できます)。ユーザーのようにActiveRecordモデルに直接リンクすると、Railsはそのモデルをmodel_pathに変換しようとするため、このユーザーを呼び出す必要があります。

于 2013-03-08T01:28:32.197 に答える
0
<%= link_to activity.owner.profile_name, activity.owner if activity.owner %>

activity.owner はタイプ user であり、user_path(activity.owner) へのリンクであると言います

レーキルートをやってみてください。user#show が定義されているかどうかを確認します。

于 2013-03-07T08:49:55.283 に答える