Spaghetti Rails 路由和邀请编码博洛尼亚
我不太确定这里是否存在单一问题,或者我是否以错误的方式处理了这个问题,但任何建议将不胜感激!
在应用程序中,当用户注册时,他们会获得权限并他们的页面设置完毕后,他们就可以通过电子邮件邀请同事。
该电子邮件末尾标有激活码。示例网址为“/user/new/xxxxxxxxx”。
问题是:我需要同事也能够仅使用他们的基本信息来创建一个用户帐户,以便他们可以登录该帐户并设置他们的应用角落。
当同事在用户注册表单上犯了错误时,网址会忘记有激活码,并会跳回验证消息和一个非常简单的“/users”网址。 当同事修改错误并单击“注册”时,他们将作为完全成熟的用户而不是受邀同事提交。
发生这种情况是因为我在“users/new”页面上有一个 if 子句
<% if @activation_code %>
Show colleague messages of invitation and happiness
<% else %>
Show fully fledged user ego stroking messages
<% end %>
我查找 url 的代码参数的路由是:
map.signup '/users/new/:code', :controller => 'users', :action => 'new', :code => nil
就像我之前所说的,我是否完全错误地处理了这个问题?这里有问题吗?
更新 这个 Rails Cast Episode 解决了我遇到的几乎所有问题: Beta 邀请
区分这个人是否来自邀请,我只是使用了这个条件块:
if [email protected]_id.blank?
效果很好。
I'm not really sure if there is a single problem here or I have approached this in the wrong way, but any suggestions would be greatly appreciated!
In the application when a user signs up they get privileges and their page gets set up, they can then invite colleagues by email.
The email has an activation code tagged on the end. An example url would be "/user/new/xxxxxxxxx".
Here's the problem: I need the colleague to be able to create a User account as well, with just their basic info, so they can log into the account and set up their corner of the app.
When the colleague makes a mistake on the user sign up form, the url forgets there is an activation code, and jumps back with validation messages and a pretty bare url of '/users'.
When the colleague amends their mistakes and clicks sign up, they are submitted as a fully fledged user, not an invited colleague.
This happens because i have an if clause on the 'users/new' page
<% if @activation_code %>
Show colleague messages of invitation and happiness
<% else %>
Show fully fledged user ego stroking messages
<% end %>
My routing to find the code parameter of the url is:
map.signup '/users/new/:code', :controller => 'users', :action => 'new', :code => nil
Like I said before, have I approached this completely wrong? is is there one problem here?
UPDATE
This Rails Cast Episode Solved nearly all of the problems I was having: Beta Invitations
Although to distinguish if the person was coming from an invitation or not I just used this conditions block:
if [email protected]_id.blank?
and that worked great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你的控制器看起来像这样:
问题是你的视图中不再有@activation_code。因此,我建议您将activation_code传回隐藏的表单字段。
这样,当您从创建操作渲染“新”视图时,您的视图仍将具有所需的 @activation_code 来帮助它渲染适当的条件元素。
Im guessing your controller looks like this:
Problem is that you dont have the @activation_code in the view anymore. So, I would suggest that you pass the activation_code back in a hidden form field.
This way when you render the "new" view from the create action your view will still have the required @activation_code to help it render the appropriate conditional elements.
他们使用确认代码访问页面后,您可能会考虑将确认代码包含在
标记中,以确保其在回发之间保存。
否则,您需要修改注册表单的操作以包含激活码;像这样的东西:
Once they've visited the page using the confirmation code, you might considering including the confirmation code in a
<input type="hidden" />
tag to insure that it's saved between postbacks.Otherwise, you need to modify the action for your sign-up form to include the activation code; something like this: