我已经安装了rails_admin到我的应用程序,我想做一些非常基本的...我有两个模型,他们的联系按预期出现......我有一个研讨会注册模型belongs_to :用户。rails_admin显示名称而不是id
在rails_admin它列出了我的研讨会注册用户为用户#1,用户#1等
我想有一个是用户的名称,而不是。我已经成功地做到的是:
config.model SeminarRegistration do
label "Seminar Signups"
# Found associations:
configure :user, :belongs_to_association
configure :seminar_time, :belongs_to_association # # Found columns:
configure :id, :integer
configure :user_id, :integer # Hidden
configure :seminar_time_id, :integer # Hidden
configure :created_at, :datetime
configure :updated_at, :datetime # # Sections:
list do
field :user do
pretty_value do
user = User.find(bindings[:object].user_id.to_s)
user.first_name + " " + user.last_name
end
end
field :seminar_time
end
export do; end
show do; end
edit do; end
create do; end
update do; end
end
的“pretty_value”节给了我我的用户名和姓的文字...但有两个问题:
1)这是没有更长的链接。如果我离开默认值(用户#1,用户#2等),它提供了一个链接到该用户。我如何获得该链接? rails_admin如何定义路径?
2)看起来太过笨重有通过ID就在那里看在我的形式...
很抱歉,如果这是一个基本的问题。我已阅读手册并查找了其他问题,但尚未完全“点击”我。我对rails也很新颖。
谢谢。
我不得不这样做是为了得到它与链接工作:
我添加了作为建议的全名的辅助方法,但保留在我的视图助手:
module ApplicationHelper
def full_name(user_id)
user = User.find(user_id)
user.first_name + " " + user.last_name
end
end
然后,我喜欢这样的“pretty_value”部分改变:
pretty_value do
user_id = bindings[:object].user_id
full_name = bindings[:view].full_name(user_id)
bindings[:view].link_to "#{full_name}", bindings[:view].rails_admin.show_path('user', user_id)
end
基本上,以访问任何观点,他lpers(导轨或其他方式作出)必须添加indings [:视图] .my_tag_to_use
要获取用户的rails_admin路线,例如,你可以这样做:
bindings[:view].rails_admin.show_path('user', user_id)
好吧,这是一个更干净的方式。但没有得到我的链接...我编辑我的答案上面,以显示我如何得到它的工作。 – user1535082 2012-09-24 20:44:47
它可以工作,但在关联查找中,您只能根据名字或姓氏进行搜索,但不能同时进行搜索。 – 2014-02-18 04:48:20
我还得到一个object_label_method的链接,关联只需要定义 – 2014-08-23 13:06:57