-1
這是我的車的控制器.. 如何在指數方法加那麼,我們將在我們的索引頁面,我想在我的車索引中顯示的用戶名
class CarsController < ApplicationController
before_action :set_car, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user! , except: [:index,:show]
def index
@cars = Car.all
end
def show
end
def new
@car = current_user.cars.build
end
def edit
end
def create
@car = current_user.cars.build(car_params)
respond_to do |format|
if @car.save
format.html { redirect_to @car, notice: 'Car was successfully created.' }
format.json { render :show, status: :created, location: @car }
else
format.html { render :new }
format.json { render json: @car.errors, status::unprocessable_entity }
end
end
end
,這讓用戶的電子郵件是我index.what在索引添加到顯示在所有的汽車用戶的電子郵件和所有ussers應該abale看到USEREMAIL
<%[email protected]%>
<div class="row" >
<% @cars.each do |car| %>
<div class="col-sm-8" >
<div class="polaroid center-block" >
<%=link_to (image_tag car.avatar.url(:medium)),car %>
<div style="float:right">
<p><%= link_to edit_car_path(car) do %>
<i class = "glyphicon glyphicon-edit "></i>
<%end %></p>
|
<p><%= link_to car, method: :delete, data: { confirm 'Are you sure?' } do %>
<i class = "glyphicon glyphicon-trash"></i>
<%end%></p></div>
</div><br>
</div>
<% end %>
我想顯示USEREMAIL的用戶誰張貼的汽車在我的索引頁。我應該在控制器中添加什麼,以及我的索引如何...
它不工作,因爲我在高職像我的索引方法添加分頁.. @ cars = Car.paginate(:page => params [:page],:per_page => 5) – aaquib