Spaghetti Rails 路由和邀请编码博洛尼亚

发布于 2024-08-24 22:38:26 字数 1193 浏览 2 评论 0原文

我不太确定这里是否存在单一问题,或者我是否以错误的方式处理了这个问题,但任何建议将不胜感激!

在应用程序中,当用户注册时,他们会获得权限并他们的页面设置完毕后,他们就可以通过电子邮件邀请同事。

该电子邮件末尾标有激活码。示例网址为“/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七堇年 2024-08-31 22:38:27

我猜你的控制器看起来像这样:

def create
  if @user = User.create(params[:user]) && @user.new_record?
    #take the user to where you want them to go
  else
    #there was an error
    flash[:error] = "Oops, blah blah blah"
    render :action => "new"
  end
end

问题是你的视图中不再有@activation_code。因此,我建议您将activation_code传回隐藏的表单字段。

def create
  @activation_code = params[:activation_code]
  if @user = User.create(params[:user]) && @user.new_record?
    #take the user to where you want them to go
  else
    #there was an error
    flash[:error] = "Oops, blah blah blah"
    render :action => "new"
  end
end

这样,当您从创建操作渲染“新”视图时,您的视图仍将具有所需的 @activation_code 来帮助它渲染适当的条件元素。

Im guessing your controller looks like this:

def create
  if @user = User.create(params[:user]) && @user.new_record?
    #take the user to where you want them to go
  else
    #there was an error
    flash[:error] = "Oops, blah blah blah"
    render :action => "new"
  end
end

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.

def create
  @activation_code = params[:activation_code]
  if @user = User.create(params[:user]) && @user.new_record?
    #take the user to where you want them to go
  else
    #there was an error
    flash[:error] = "Oops, blah blah blah"
    render :action => "new"
  end
end

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.

苹果你个爱泡泡 2024-08-31 22:38:27

他们使用确认代码访问页面后,您可能会考虑将确认代码包含在 标记中,以确保其在回发之间保存。

否则,您需要修改注册表单的操作以包含激活码;像这样的东西:

form_for @user, :url => "/users/new/#{@activation_code}" do |f|
# ...
end

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:

form_for @user, :url => "/users/new/#{@activation_code}" do |f|
# ...
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文