undefined method `to_model' in rails -


i have following activeadmin model

class adminuser < activerecord::base has_many :challenges    devise :database_authenticatable,           :recoverable, :rememberable, :trackable, :validatable end 

and following challenge model

class challenge < activerecord::base     belongs_to :subdomain     belongs_to :admin_user      has_many :comments, :dependent => :destroy  end 

i defined following method in application.html.erb

 helper_method :all_admin_users    def all_admin_users      @users = adminuser.all   end 

adminuser has following attributes :id,:name,:email when try access challenges of particular user

<ul> <% all_admin_users.each |user| %> <li> <%= link_to user.name ,user.challenges%></li> <br /> <% end %> </ul> 

i following error "undefined method `to_model' challenge::activerecord_associations_collectionproxy

here's routes.rb file

rails.application.routes.draw   resources :comments   devise_for :admin_users, activeadmin::devise.config    'subdomains/index'    'subdomains/edit'    'subdomains/new'    'subdomains/show'    'home/index'      root 'home#index'    resources :challenges   resources :subdomains   activeadmin.routes(self) end 

first in routes file need add action list users-challenged

in routes.rb @ end add

get 'users/:user_id/challenges' => 'challenges#user_challenges', as: :user_challenges # way have action view users challenges # inside challenges controller 

in challenges_controller.rb add action user_challenges

def user_challenges   @challenges = challenge.where(admin_user_id: params[:user_id]) end 

create view action, , display challenges

then can create link action

<ul>   <% all_admin_users.each |user| %>     <li> <%= link_to user.name , user_challenges_path(user.id)%> </li>     <br />   <% end %> </ul> 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -