私はここにレールニューブラーのビットがあり、これを理解する助けが必要です。私は新しい「トピック」を作成したり編集したりするたびにスローされる引数エラーがあります。トピックのArgumentError#可能なDeviseエラーを表示しますか?
ここで "ショー" のためのコードである:
class TopicsController < ApplicationController
def index
@topics = Topic.all
end
def show
@topic = Topic.find(params[:id])
end
def new
@topic = Topic.new
end
def create
@topic = Topic.new(topic_params)
if @topic.save
flash[:notice]= "Topic was saved."
redirect_to @topic
else
flash.now[:alert]= "The topic could not be saved. Please try again"
render :new
end
end
def edit
@topic = Topic.find(params[:id])
end
def update
@topic = Topic.find(params[:id])
@topic.assign_attributes(topic_params)
if @topic.save
flash[:notice]= "The topic was saved sucessfully."
redirect_to @topic
else
flash.now[:alert]= "There was an error saving the topic. Please try again."
render :edit
end
end
def destroy
@topic = Topic.find(params[:id])
if @topic.destroy
flash[:notice]= "\"#{@topic.title}\" was deleted successfully."
redirect_to topics_path
else
flash.now[:alert] = "There was an error in deleting this topic."
render :show
end
end
def topic_params
params.require(:topic).permit(:title)
end
end
更新(1ここ
<h1><%= @topic.title %></h1>
<%= link_to "Edit", edit_topic_path(@topic), class: 'btn btn-success' %>
<%= link_to "Delete Topic", @topic, method: :delete, class: 'btn btn-danger', data: {confirm: 'Are you sure you want to delete this topic?'} %>
<% if policy(Bookmark.new).create? %>
<%= link_to "New Bookmark", new_topic_bookmark_path(@topic), class: 'btn btn-success' %>
<% end %>
<% @topic.bookmarks.each do |bookmark| %>
<div class="media-body">
<div class="row">
<div class="col-md-2">
<div class="container">
<img src="http://icons.better-idea.org/icon?url=<%= bookmark.url %>&size=120">
<div class="media-heading">
<%= link_to bookmark.name, topic_bookmark_path(@topic, bookmark) %>
</div>
</div>
</div>
</div>
<div class="col-md-1">
<%= render partial: 'likes/like', locals: {bookmark: bookmark} %>
</div>
</div>
<% end %>
は "トピック" コントローラであります): "ポリシー" 01を削除した後の新しいエラーここで
は評論家を使用する「アプリケーションポリシーです:
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
raise Pundit::NotAuthorizedError, "must be logged in" unless user
@user = user
@record = record
end
def index?
false
end
def show?
scope.where(:id => record.id).exists?
end
def create?
user.present?
end
def new?
create?
end
def update?
user.present? && (record.user == user)
end
def edit?
update?
end
def destroy?
user.present? && (record.user == user)
end
def scope
Pundit.policy_scope!(user, record.class)
end
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
scope
end
end
end
あなたは、取得しているエラーを投稿することができます – MZaragoza
引数エラーは、画像へのリンクです。 http://i.stack.imgur.com/jN7Gj.png –
ポリシーなしで試しましたか? ( 'link_to"のみ新しいブックマーク "..') – BriceB