Ruby Sinatra路线未被认可

发布于 2025-01-20 12:30:43 字数 1712 浏览 2 评论 0原文

我遇到了一些问题,Sinatra 无法识别我的路线(所有其他路线都工作正常,只是这组特定的 4 条路线)。布局是:在我的 views 中,用户单击与 /all /inactive / 路由相对应的过滤器按钮active/expired,并且应根据此选择进行过滤。

这是 index.haml 过滤器:

%form{method: 'GET', action: "/showings/all"}
      %input#all.btn.btn-md.btn-secondary{type: 'submit', value: 'All'}
%form{method: 'GET', action: "/showings/active"}
      %input#active.btn.btn-md.btn-secondary{type: 'submit', value: 'Active'}
%form{method: 'GET', action: "/showings/inactive"}
      %input#inactive.btn.btn-md.btn-secondary{type: 'submit', value: 'Inactive'}
%form{method: 'GET', action: "/showings/expired"}
      %input#expired.btn.btn-md.btn-secondary{type: 'submit', value: 'Expired'}
%form{method: 'DELETE', action: "/showings/delete", style: "padding-left: 45%"}
      %input#delete.btn.btn-md.btn-danger{type: 'submit', value: 'Delete Expired Hosted Screenings'}

但是,在 controllers 文件夹中的 showings_routes.rb 文件中,我尝试了这些路由,但它们从未得到已注册(我已尝试重新启动网络应用程序):

get '/all' do
    p "ALL ROUTES"
    haml :'showings/index'
  end

  get '/active' do
    p "ACTIVE ROUTES"
    haml :'showings/index'
  end

  get '/inactive' do
    p "INACTIVE ROUTES"
    haml :'showings/index'
  end

  get '/expired' do
    p "EXPIRED ROUTES"
    haml :'showings/index'
  end

  delete '/delete' do
    p "DELETE ROUTES"
    redirect '/showings'
  end

我计划稍后添加过滤器逻辑,当我单击其中一个按钮或导航到 localhost:3000/showings/all 时,路线不会被识别。我只是很困惑,因为这是一个内置的网络应用程序,所以 showings_routes.rb 文件中的所有其他路由都工作正常(例如 /create /submit< /code> 等)

当我在应用程序中处理路由时,是否遗漏了什么?

I'm having some issues with Sinatra not recognizing my routes (all other routes work fine, it is just this specific set of 4 routes). The layout is: in my views, the user clicks on a filter button which corresponds to the route of /all /inactive /active or /expired, and should filter out based on this selection.

Here is the index.haml filters:

%form{method: 'GET', action: "/showings/all"}
      %input#all.btn.btn-md.btn-secondary{type: 'submit', value: 'All'}
%form{method: 'GET', action: "/showings/active"}
      %input#active.btn.btn-md.btn-secondary{type: 'submit', value: 'Active'}
%form{method: 'GET', action: "/showings/inactive"}
      %input#inactive.btn.btn-md.btn-secondary{type: 'submit', value: 'Inactive'}
%form{method: 'GET', action: "/showings/expired"}
      %input#expired.btn.btn-md.btn-secondary{type: 'submit', value: 'Expired'}
%form{method: 'DELETE', action: "/showings/delete", style: "padding-left: 45%"}
      %input#delete.btn.btn-md.btn-danger{type: 'submit', value: 'Delete Expired Hosted Screenings'}

However, in my showings_routes.rb file in my controllers folder, I tried these route but they never get registered (I've tried restarting the web app):

get '/all' do
    p "ALL ROUTES"
    haml :'showings/index'
  end

  get '/active' do
    p "ACTIVE ROUTES"
    haml :'showings/index'
  end

  get '/inactive' do
    p "INACTIVE ROUTES"
    haml :'showings/index'
  end

  get '/expired' do
    p "EXPIRED ROUTES"
    haml :'showings/index'
  end

  delete '/delete' do
    p "DELETE ROUTES"
    redirect '/showings'
  end

I'm planning on adding the filter logic later, the routes are just not being recognized when I click one of the buttons or navigate to localhost:3000/showings/all. I'm just confused because this is a built web app, so all the other routes in the showings_routes.rb file work fine (like /create /submit etc.)

Is there a thing that I'm missing when I'm handling my routes here in my application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文