Reputation: 89
I am trying to get 2 action showing on the one view.
routes.rb
resources :users do
get "accepted", to: "users#accepted"
users_controller.rb
def show
@user = User.find(params[:id])
@requests = @user.requests
end
def accepted
@user = User.find(params[:id])
@requests = Request.where(:driverid => @user.id).order("created_at DESC")
end
I am trying to point these two actions to the users view page.
Ive been playing around with partials and looking at similar questions but cant figure it out. Any help is appreciated!
EDIT
show.html.haml
I want the below to be the show action:
%h2 Current requests:
- @user.requests.where(:accepted => 'f').each do |request|
etc
Then the accepted action:
- @requests.where(blah blah).each do |request|
etc
Upvotes: 1
Views: 119
Reputation: 28305
From the Rails documentation:
def accepted
@user = User.find(params[:id])
@requests = Request.where(:driverid => @user.id).order("created_at DESC")
render :show
end
EDIT:
In the controller show action:
@requests = @user.requests.where(:accepted => 'f')
And in the show view:
%h2 Current requests:
- @requests.each do |request|
# ...
Upvotes: 1