Ruby on Rails 参量
示例
控制器可以访问HTTP参数(您可能知道它们?name=foo在URL中,但是RubyonRails也可以处理不同的格式!),并根据它们输出不同的响应。没有办法区分GET和POST参数,但是无论如何都不应该这样做。
class UsersController < ApplicationController
def index
respond_to do |format|
format.htmldo
if params[:name] == "john"
render html: "Hello John"
else
render html: "Hello someone"
end
end
end
end
end和往常一样,我们的路线:
resources :users, only: [:index]
访问URL/users?name=john,输出为HelloJohn,访问/users?name=whatever和输出为Hellosomeone
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志