Rails 自定义操作

发布于 2024-09-27 09:05:07 字数 213 浏览 0 评论 0原文

我不确定我是否以正确的方式处理这件事。

我有一个模范社区。我有两种方法可以添加邻居,一种是作为登录用户,另一种是作为公众。形式略有不同。所以我用自定义操作制作了另一个视图。问题是此操作正在添加新记录,因此需要“创建”。当它调用创建操作时,它会重定向到公共表单上不存在的路径。

要么我做的完全错误,要么有一种方法可以告诉我的自定义操作来保存邻里记录,以便我可以在公共方面进行重定向。

I am not sure if I am going about this the right way or not.

I have a model Neighborhood. I have a two ways you can add a neighborhood, one as a logged in user and the other as a public person. The forms vary a bit. So I made another view with a custom action. The problem is this action is adding a new record and therefore calls on "create." When it calls the create action it looks to redirect to a path that cannot exist on the public form.

Either I am doing this completely wrong or there is a way to tell my custom action to save the Neighborhood record so I can redirect on the public side.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

我最亲爱的 2024-10-04 09:05:07

create 操作中,根据用户的状态有条件地重定向到公共/私人页面:

def create
  # create code goes here
  if current_user?
    redirect_to neighborhoods_path
  else
    redirect_to root_path
  end
end

或者是否有我从您的问题中无法理解的内容?

In the create action, conditionally redirect to either the public / private page depending on the user's status:

def create
  # create code goes here
  if current_user?
    redirect_to neighborhoods_path
  else
    redirect_to root_path
  end
end

Or is there something that I am not understanding from your question?

失退 2024-10-04 09:05:07

我认为您正在保存两者(公共用户和注册用户),邻里详细信息将添加到相同的详细信息中。你可能会通过拥有用户 ID 或其他东西来改变这一点

,如果是的话,正如我所见,你可以使用相同的控制器和操作。您所要做的就是

识别用户,例如 is_registred? (假设您有一种方法来识别是否记录了使用)并且根据用户加载布局,只有

Ex:

伪代码,

if is_registred?
   render public layout
else
   render registerd user layout   

并且您可能还必须检查授权。希望我理解你的问题,

干杯

为Sameera

i think you are saving both (public and registered users), the Neighborhood details are added to the same details. you might different this by having a user id or something

if so, As i see you can use the same controller and action. All you have to do is

identify the user like is_registred? (provided that you have a method to identify if a use is logged or not) and according to the user load layout only

Ex:

pseudo code would be

if is_registred?
   render public layout
else
   render registerd user layout   

and you might have to check authorizations as well. Hope I understood your question

cheers

sameera

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文