English 中文(简体)
铁路第3号,通过中间页获取对象代号
原标题:Rails 3, obtaining an object s id through an intermediate page

我与三个模型合作:用户、项目和用户特权。用户特权模式由用户身份、项目身份和访问级别价值组成。用户和项目模式与用户特权有多种关系,并通过彼此的关系拥有许多关系。

当用户创建工程时, 在用户权限表中创建相应的条目 。 我不知道如何为用户与另一个用户共享项目的情形创建这样的条目 。 在这种情况下, 用户会访问项目页面, 点击链接以共享项目访问权限, 并指定目标用户的电子邮件 。

我将这种情况与用户权限控制器中的新动作联系起来。 在创建动作中,我可以访问与项目共享的用户对象( 使用电子邮件 id ), 但我不确定如何共享项目的项目代号 。 当用户访问项目页面并点击共享访问链接时, 是否有办法存储项目代号?

谢谢


由于Aldos的评论,我得以解决了这个问题。但是,我有一个相关的问题:能否使用路线.rb文件来解决这个问题。我能否将项目路线中的用户特权行动路线包括在内?例如:/Project/1/userprivileges/ new或/project/1/userprivefilges/1/edit。然后,我就可以从URI得到项目id。但是,一个限制是必要的,即用户特权只能从与他们有关的项目中获得,因此,诸如/project/projectruterpriveliges/1/edit之类的东西是不允许的。我怎么能执行这种限制呢?

最佳回答

您应该将 project_id 传送到 Userprivilegas Conserence# new 。 请使用 link_to 选项来在您的工程视图中做到这一点, 例如 :

# app/views/project.html.erb
<%= link_to "Share access", {controller:  userprivileges , action:  new , project_id: @project.id}

一旦在控制器中,您就会从使用 params[:project_id] ] 参数的参数中获得这个数值,然后用隐藏的字段(使用 hidden_field >>hidden_field_tag

想法是当用户提交表单时通过 project_id ,这样 Userprivileges control#cape 动作就可以使用(再次 params[:project_id] )访问它。

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...