![]() 蕲春人 0.291% disconnected | 登录后回复主题 | 切换简介显示 | 跳到回复(7) Rails2.1中如何新加一个action方法?
|
1 - 6-19 15:48
bd7lx 深圳routes.rb
里
ActionController::Routing::Routes.draw do |map|
map.xxxs 'xxxs',
:controller => "xxxs",
:action => "login"
end
里
ActionController::Routing::Routes.draw do |map|
map.xxxs 'xxxs',
:controller => "xxxs",
:action => "login"
end
2 - 6-19 21:17
markliu 地球一个RESTful不应该包含login方法,你应该把对应的map.resources声明去掉,就会使用environment.rb最下面的map/:controller/:action/:id方式对应到你想要的login方法中了
5 - 6-27 19:27
蕲春人 楼主 地球一个RESTful不应该包含login方法,你应该把对应的map.resources声明去掉,就会使用environment.rb最下面的map/:controller/:action/:id方式对应到你想要的login方法中了
不明白你第二句是什么意思.
你说不应该包含login方法?我的做法现在是再创建一个Login的controller,这样好不好呢?
不明白你第二句是什么意思.
你说不应该包含login方法?我的做法现在是再创建一个Login的controller,这样好不好呢?
6 - 6-27 19:28
蕲春人 楼主 地球老外说的
Yeah, but why would you want to make something work that is so obviously wrong?
Think about it from a REST perspective: There's collections of resources (e.g. /users) and there's single items/members (e.g. /users/1). Where does the login action go? It obviously doesn't fit for the collection (you're trying to log in one users, not multiple) and it doesn't work for a member because at the moment of login you don't know which member (i.e. user) you're talking about. It just doesn't make any sense!
Also, take a look at the route you've created: login_new_user_path doesn't make sense - only existing users can log in!
Let me say it again: Have custom actions whenever they're necessary. If they're not necessary, leave them out.
Stuff that makes sense:
- bulk actions (e.g. deleting/activating/blocking/etc. multiple users) -> collection action that takes multiple user ids as params
- actions that change the state (e.g. activate/block/unblock/etc. a single user) -> member action
Of course, the implementation of these things doesn't necessarily have to be inside the User model, e.g. if you want users to block each other (e.g. private messaging), you might have a Block resource and internally call Block.create inside /users/block action.
Yeah, but why would you want to make something work that is so obviously wrong?
Think about it from a REST perspective: There's collections of resources (e.g. /users) and there's single items/members (e.g. /users/1). Where does the login action go? It obviously doesn't fit for the collection (you're trying to log in one users, not multiple) and it doesn't work for a member because at the moment of login you don't know which member (i.e. user) you're talking about. It just doesn't make any sense!
Also, take a look at the route you've created: login_new_user_path doesn't make sense - only existing users can log in!
Let me say it again: Have custom actions whenever they're necessary. If they're not necessary, leave them out.
Stuff that makes sense:
- bulk actions (e.g. deleting/activating/blocking/etc. multiple users) -> collection action that takes multiple user ids as params
- actions that change the state (e.g. activate/block/unblock/etc. a single user) -> member action
Of course, the implementation of these things doesn't necessarily have to be inside the User model, e.g. if you want users to block each other (e.g. private messaging), you might have a Block resource and internally call Block.create inside /users/block action.
7 - 6-27 20:43
robin 北京市海淀区如果只是login的问题,看一下restful_authentication的做法吧。
如果是普通的加一个action方法,3楼已经回答得很明白了用:collection或者:member都可以。
如果是普通的加一个action方法,3楼已经回答得很明白了用:collection或者:member都可以。
回到顶部 | Rails | 返回 ChinaonRails 首页 | 注册 | 找回密码












