我有一个activeadmin资源,它具有belongs_to:user关系.
当我在活动管理员中创建模型的新实例时,我想将当前登录的用户关联为创建实例的用户(我想象的非常标准的东西).
所以......我得到了它:
controller do
def create
@item = Item.new(params[:item])
@item.user = current_curator
super
end
end
Run Code Online (Sandbox Code Playgroud)
但是;)我只是想知道这是如何工作的?我只是希望将@item变量分配给用户,然后调用super将起作用(并且确实如此).我也开始浏览宝石,但看不出它是如何工作的.
任何指针都会很棒.我假设这是InheritedResources给你的东西?
谢谢!
我知道有一些Java的ActiveResource 客户端库,比如RAPA和JactiveResource
问题是:有没有简单的方法在Java中创建ActiveResource 的服务器端?
在RubyOnRails中,您需要做的就是使用Inherited Resources gem.Java中有类似的东西吗?
我正在将Rails 3.1.3用于具有Inherited Resources 1.3.0的项目.
当我有这样的控制器时:
class PostsController < InheritedResources::Base
end
Run Code Online (Sandbox Code Playgroud)
我用rspec测试以下内容
describe "PUT update" do
describe "with invalid params" do
it "re-renders the 'edit' template" do
post = Post.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Post.any_instance.stub(:save).and_return(false)
put :update, {:id => post.to_param, :post => {}}, valid_session
response.should render_template("edit")
end
end
end
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
3) PostsController PUT update with invalid params re-renders the 'edit' template
Failure/Error: response.should render_template("edit")
expecting <"edit"> but rendering with <"">
# ./spec/controllers/posts_controller_spec.rb:115:in `block …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有rails 3.1的ActiveAdmin,但在得到以下内容时出现以下错误rails generate active_admin:install:
gems/activeadmin-0.3.0/lib/active_admin/namespace.rb:176:in `eval': uninitialized constant InheritedResources::Base (NameError)
Run Code Online (Sandbox Code Playgroud)
现在任何generate/destroy命令都会发生这种情况.我已经确保我已经在github wiki上的安装指令中添加了所需的3.1 gems(sass-rails和meta_search).有没有人有任何想法?
ruby-on-rails inherited-resources ruby-on-rails-3.1 activeadmin
有没有人成功使用Rails 3,Mongoid和Inherited Resources?有任何提示可以实现吗?我很乐意使用这两种宝石.
目前我遇到:
undefined method `scoped'
Run Code Online (Sandbox Code Playgroud)
关于索引操作.
谢谢!
BTW范围问题的解决方法是覆盖集合,如下所示:
class CampaignsController < InheritedResources::Base
def collection
@campaigns ||= end_of_association_chain.paginate(:page => params[:page])
end
end
Run Code Online (Sandbox Code Playgroud)
但我正在寻找一种更全面的方法
ruby-on-rails mongodb mongoid inherited-resources ruby-on-rails-3
我在我的Rails 3应用程序中使用active_admin gem,它具有依赖inherited_resources.我有点像newb,宁愿为我自己的控制器避免使用inherited_resources的黑盒子质量,但是,当我运行默认的rails g scaffold命令时,生成的控制器继承自inherited_resources.我知道我可以通过继承ApplicationController手动覆盖它,但是,如果可能的话,我希望能够生成默认的rails支架.
我试过在rails4 app中使用IR,但是我的代码
class WorkspacesController < InheritedResources::Base
private
def permitted_params
params.permit(:workspace => [:name, :owner_id])
end
end
Run Code Online (Sandbox Code Playgroud)
引发ActiveModel :: ForbiddenAttributesError异常.
以下代码存在同样的问题
def permitted_params
params.permit(:name, :owner_id)
end
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?
PS:我已经尝试过关注原型http://blog.josemarluedke.com/posts/inherited-resources-with-rails-4-and-strong-parameters但是使用4.0rc1它不起作用:(
我想通过activeadmin创建设置页面(编辑/更新). https://github.com/huacnlee/rails-settings-cached.
但我面临着没有办法在特定页面的路由中注册资源(而不是资源),例如有/ admin/settings之类的路由,但不是admin/settings /:id
inherit_resource有
defaults singleton: true
Run Code Online (Sandbox Code Playgroud)
对于这种情况,但这对activeadmin不起作用.
请帮忙.
否则,我可以使用register_pagse方式自己创建表单并更新操作,但是出现了另一个问题:如何从该更新操作在表单上呈现错误消息.
单身方式是首选方式.
首先,我喜欢inherited_resources
考虑以下:
class Job < ActiveRecord::Base
has_many :inputs, dependent: :destroy
has_one :output
end
class JobsController < InheritedResources::Base
respond_to :json
end
Run Code Online (Sandbox Code Playgroud)
当我请求jobs/1.json时,我只获取作业对象的JSON.我想要的还有要包含的输入和输出.我通常通过以下方式实现:
job.to_json(include: [:inputs,:output])
我的问题是用IR实现这一目标的最佳方法是什么?现在,我只是覆盖节目,但我想知道是否有更优雅的方式?
谢谢!
如何在Activeadmin中为我的所有资源挽救ActiveRecord :: RecordNotFound?
我知道在Rails中我可以放入rescue_from(ActiveRecord::RecordNotFound)ApplicationController,在ActiveAdmin中有相同的方法吗?
ruby-on-rails inherited-resources activeadmin ruby-on-rails-4
使用以下Store和Service模型,使用MongoMapper进行管理:
class Store
include MongoMapper::Document
key :service_ids, Array, :typecast => 'ObjectId'
many :services, :in => :service_ids
end
class Service
include MongoMapper::Document
key :name, String
many :stores, :foreign_key => :service_ids
end
Run Code Online (Sandbox Code Playgroud)
我有这个表格,用Formtastic完成:
<%= semantic_form_for @store, :url => admin_store_path(@store), :method => :put do |form| %>
<%= form.input :service_ids, :label => "Select Store Services",
:as => :check_boxes,
:collection => Service.all %>
<% end -%>
Run Code Online (Sandbox Code Playgroud)
控制器使用Inherited Resources,编辑操作是隐式的.
使用已与之关联的服务编辑@store时,后者的复选框不会显示为已选中.
Formtastic的README警告它不正式支持MongoMapper,但它也说人们已经成功地使用了两者,我在网上看到了一些这样的例子.
我怀疑Inherited Resources也不支持它,我从Devise + Simple Form看到的,都来自同一作者,不支持MM.他们正努力在他们的宝石中使用ORM适配器,但尚未准备好AFAIK.
我已经遇到了问题,我正在重写更新操作以使其工作:
def update
store = Store.find(params[:id])
if …Run Code Online (Sandbox Code Playgroud) activeadmin ×4
formtastic ×1
java ×1
json ×1
mongodb ×1
mongoid ×1
mongomapper ×1
rest ×1
ruby ×1