Вопрос

I have this configuration in the controller in Padrino

MyProject::App.controllers do
  get '/'  do
    handlebars :index
  end

  get :file, :with => :tokenId   do
    tokenId = params[:tokenId]

    [extra logic]
  end
end

GET / works.

GET /file/abc doesn't.

GET /file/:tokenId works!

It looks like :token is not recognized as a parameter placeholder in the route definition.

I've tried

get "/file/:tokenId"

too but with no luck.

I can't find any information on any similar issue, anybody can help? Happy to add more information if needed.

Это было полезно?

Решение

Okay so I am unsure why the change made a difference but camelCase is generally considered poor syntax for variables in ruby.(Padrino may be calling a method such as underscore on your variable i.e.

"tokenID".underscore.to_sym 
#=>:token_id

Using underscored_variables instead. (e.g. :tokenID becomes :token_id. This structure also allows for interacting with databases in a nicer way as well since your columns will have names such as token_id not tokenID.

There are uses for camelCasing in ruby and rails such as class naming and generators but trying keep all local and instance variables in lowercase underscore format.

I don't do much work in padrino so I am not 100% sure why this change helped but I am glad I could help.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top