Rails 自定义操作
我不确定我是否以正确的方式处理这件事。
我有一个模范社区。我有两种方法可以添加邻居,一种是作为登录用户,另一种是作为公众。形式略有不同。所以我用自定义操作制作了另一个视图。问题是此操作正在添加新记录,因此需要“创建”。当它调用创建操作时,它会重定向到公共表单上不存在的路径。
要么我做的完全错误,要么有一种方法可以告诉我的自定义操作来保存邻里记录,以便我可以在公共方面进行重定向。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
create
操作中,根据用户的状态有条件地重定向到公共/私人页面:或者是否有我从您的问题中无法理解的内容?
In the
create
action, conditionally redirect to either the public / private page depending on the user's status:Or is there something that I am not understanding from your question?
我认为您正在保存两者(公共用户和注册用户),邻里详细信息将添加到相同的详细信息中。你可能会通过拥有用户 ID 或其他东西来改变这一点
,如果是的话,正如我所见,你可以使用相同的控制器和操作。您所要做的就是
识别用户,例如 is_registred? (假设您有一种方法来识别是否记录了使用)并且根据用户加载布局,只有
Ex:
伪代码,
并且您可能还必须检查授权。希望我理解你的问题,
干杯
为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
and you might have to check authorizations as well. Hope I understood your question
cheers
sameera