我正在处理活动的admin gem.我只想隐藏显示页面中的删除链接.所以,我添加了以下代码
ActiveAdmin.register ArticlesSkill do
menu :parent => "ReadUp"
actions :index, :show, :new, :create, :update, :edit
index do
column :name, sortable: :name
column :description
column "" do |resource|
links = ''.html_safe
links += link_to I18n.t('active_admin.view'), resource_path(resource), :class => "member_link edit_link"
links += link_to I18n.t('active_admin.edit'), edit_resource_path(resource), :class => "member_link edit_link"
if Article.where(articles_skill_id: resource.id).blank?
links += link_to I18n.t('active_admin.delete'), resource_path(resource), :method => :delete, :confirm => I18n.t('active_admin.delete_confirmation'), :class => "member_link delete_link"
else
# links += link_to I18n.t('active_admin.delete'), "#", :confirm => ("This Skill …Run Code Online (Sandbox Code Playgroud) def confirm_invite_new_tutor
redirect_with_msg = false
@game_school = GameSchool.find(params[:id])
existing_user_emails = params[:all_emails][:existing_user] || []
new_users = params[:param_game_school][:game_school_invites_attributes]
if existing_user_emails.present?
existing_user_emails.each do |existing_user|
// some code
end
redirect_with_msg = true
end
if new_users.present?
if @game_school.update_attributes(params[:param_game_school])
redirect_with_msg = true
else
render :invite_tutor_form
end
end
if redirect_with_msg
redirect_to @game_school, notice: "daw"
else
redirect_to @game_school
end
end
Run Code Online (Sandbox Code Playgroud)
如果我正在执行此操作,我会收到错误
在此操作中多次调用渲染和/或重定向.请注意,您只能调用渲染或重定向,每次操作最多一次.另请注意,重定向和呈现都不会终止操作的执行,因此如果要在重定向后退出操作,则需要执行类似"redirect_to(...)并返回"的操作.
如果我使用return它将我带到其他页面,甚至不显示flash msg.如何解决这个问题?
我正在尝试创建一篇文章.
class Article < ActiveRecord::Base
belongs_to :article_skill
attr_accessible :articles_skill_attributes
accepts_nested_attributes_for :articles_skill
end
class ArticlesSkill < ActiveRecord::Base
attr_accessible :description, :name
has_many :articles
end
Run Code Online (Sandbox Code Playgroud)
这是我的形式 article/new.html.erb
<%= article_form.fields_for :articles_skill, @article.articles_skill do |b|%>
<label class="medium"><span class="red">*</span> Skill</label>
<%= b.select :id, options_for_select(ArticlesSkill.all.collect{|m| [m.name, m.id]}) %>
<%end%>
Run Code Online (Sandbox Code Playgroud)
这article_form是@article表单对象的构建器.
如果我尝试保存@article对象,则显示此错误.
Couldn't find ArticlesSkill with ID=1 for Article with ID=
Run Code Online (Sandbox Code Playgroud)