ユーザーの画像に投稿一覧へ飛べるリンクを張りたい
Q&A
Closed
解決したいこと
Ruby on Railsで本の感想を投稿できるサイトを作っています。
ユーザーの画像にそのユーザーの投稿一覧へ飛べるリンクを張りたいのですが、
link_toではどのようにしてもsyntaxerrorがでてしまいます。
当方、プログラミング初心者なのでわからないことが多いので初歩的な
ことかもしれませんがよろしくお願いいたします。
リンクを張る前はエラーは出ていません、またdevise,refile,bootstrap,fontawesomeを使用しています。
発生している問題・エラー
SyntaxError in BooksController#index
/home/ec2-user/environment/bookers2/app/views/books/index.html.erb:26: syntax error, unexpected ',', expecting ')' ..._tag book.user (:profile_image, :fill, fallback: "no_image... ... ^ /home/ec2-user/environment/bookers2/app/views/books/index.html.erb:26: syntax error, unexpected ',', expecting ')' ...ll, fallback: "no_image.jpg",size: "40x40") "user_path(boo... ... ^ /home/ec2-user/environment/bookers2/app/views/books/index.html.erb:26: syntax error, unexpected tSTRING_BEG, expecting end ..."no_image.jpg",size: "40x40") "user_path(book.user)" );@outp... ... ^ /home/ec2-user/environment/bookers2/app/views/books/index.html.erb:26: syntax error, unexpected ')', expecting end ...0x40") "user_path(book.user)" );@output_buffer.safe_append=' ... ^ /home/ec2-user/environment/bookers2/app/views/books/index.html.erb:39: syntax error, unexpected ensure, expecting end-of-input ensure ^~~~~~
該当するソースコード views/books/index
<div class="container px-5 px-sm-0">
<div class="row">
<%= render 'books/side', book: @book, user: current_user %>
<div class="col-md-8 offset-md-1">
<h2>Books</h2>
<table class="table table-hover table-inverse">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>Opinion</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody><% @books.each do |book| %>
<tr>
<td>
<%= link_to attachment_image_tag book.user, :profile_image, :fill, fallback: "no_image.jpg",size: "40x40", "user_path(book.user)" %>
</td>
<td><%= link_to book.title, book_path(book) %></td>
<td><%= book.body %></td>
</tr>
</tbody><% end %>
</table>
</div>
</div>
</div>
該当するソースコード controllers/books_controller
class BooksController < ApplicationController
def new
@book = Book.new
end
def create
@books = Book.all
@book = Book.new(book_params)
@book.user_id = current_user.id
if @book.save
redirect_to book_path(@book), notice: 'You have created book successfully.'
else
render :index
end
end
def index
@books = Book.all
@book = Book.new
end
def show
@book = Book.find(params[:id])
@user = @book.user
@book_new = Book.new
end
def edit
@book = Book.find(params[:id])
if @book.user == current_user
render "edit"
else
redirect_to books_path
end
end
def update
@book = Book.find(params[:id])
@book.update(book_params)
if @book.save
redirect_to book_path(@book), notice: 'You have updated book successfully.'
else
render :edit
end
end
def destroy
@book = Book.find(params[:id])
@book.destroy
redirect_to books_path
end
private
def book_params
params.require(:book).permit(:title, :body)
end
end
自分で試したこと
画像の詳細指定を()で囲ったりしましたが全てエラーとなりました。
0 likes