Reputation: 45
I have something like this
get '/news/:news_slug/' do
...
end
What I've trying to do is access the news_slug
in a before
block, is there anyway to do that?
Upvotes: 2
Views: 944
Reputation: 1088
I've tried to do something like this myself, what I had to do was use the before
block like so:
before '/news/:news_slug' do
# Before news code
end
However, if you want to use the before block for other stuff also, you'll have to do what I did which is something like:
def news_before
# Before news code
end
["/url_one", "/url_two", "/news/:news_slug"].each do |path|
before path do
if params[:news_slug]
news_before
end
end
end
Hope this helps you.
Upvotes: 2