- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我以前从未遇到过这个问题。我收到此错误。
No route matches [GET] "/recipes/1/like"
这是我的 routes.rb:
Rails.application.routes.draw do
root 'pages#home'
get '/home', to: "pages#home"
resources :recipes do
member do
post 'like'
end
end
end
这是我的 recipes_controller:
def like
@recipe = Recipe.create(params[:id])
Like.create(like: params[:like], chef: Chef.first, recipe: @recipe)
#flash message
flash[:success] = "Your selection was sucessful"
redirect_to :back
end
这是我的 html.erb 文件:
<%= render 'shared/page_title', title: @recipe.name.titleize %>
<div class= "row">
<div class="col-md-4 pull-right center">
<%= gravator_for @recipe.chef, size: 200 %>
<p>
<h5>Brought to you by: <%= @recipe.chef.chefname.capitalize %></h5>
</p>
</div>
<div class= "col-xs-8 col-md-8">
<%= link_to "Edit this Recipe", edit_recipe_path(@recipe), class: "btn btn-success pull-right" %>
<h3><%= @recipe.summary.capitalize %></h3>
<div class="show_recipe">
<%= image_tag(@recipe.picture.url, size: "300x200", class: "recipe-image") if @recipe.picture? %>
</div>
<div class ="well recipe-description">
<p>
<strong> Steps:</strong>
</p>
<%= simple_format(@recipe.description) %>
<div class="pull-right">
<%= link_to like_recipe_path(@recipe, like: true), method: :post do %>
<i class="glyphicon glyphicon-thumbs-up"></i>
<% end %>     
<%= link_to like_recipe_path(@recipe, like: false), :method => :post do %>
<i class="glyphicon glyphicon-thumbs-down"></i>
<% end %>
</div>
</div>
</div>
</div>
<h5><%= link_to "Return to Recipes Listings", recipes_path, class: "btn btn-warning btn-small" %></h5>
我已经明确地将 HTTP POST 请求添加到我的 html.erb 文件中
%= link_to like_recipe_path(@recipe, like: true), method: :post do %>
但 rails 提示没有 GET 路由请求,我从未在我的路由中创建该请求,因为我需要对 Web 应用程序的这个特定部分进行 POST 请求。
rake 路线:
Prefix Verb URI Pattern Controller#Action
root GET / pages#home
home GET /home(.:format) pages#home
like_recipe POST /recipes/:id/like(.:format) recipes#like
recipes GET /recipes(.:format) recipes#index
POST /recipes(.:format) recipes#create
new_recipe GET /recipes/new(.:format) recipes#new
edit_recipe GET /recipes/:id/edit(.:format) recipes#edit
recipe GET /recipes/:id(.:format) recipes#show
PATCH /recipes/:id(.:format) recipes#update
PUT /recipes/:id(.:format) recipes#update
DELETE /recipes/:id(.:format) recipes#destroy
老实说,我迷路了。似乎一切都在正确的地方。
rails 版本:
Rails 4.2.5
我已经定义了操作,创建了 like 模型,将路由嵌套在 recipes 下,并在 html.erb 页面中明确请求了一个 post HTTP 请求。
任何想法都会很棒!
干杯!
最佳答案
这是我的工作项目中具有类似安排的相关代码。
# /views/events/splits.html.erb:
<%= link_to "Add",
associate_splits_event_path(id: @event.id, split_ids: [split.id]),
:method => :put,
:class => 'btn btn-xs btn-success' %>
# routes.rb
resources :events do
member { put :associate_splits }
end
如果在上下文中查看它有帮助,请随意浏览存储库。这是 View 的链接:https://github.com/SplitTime/OpenSplitTime/blob/master/app/views/events/splits.html.erb
关于ruby-on-rails - 没有路由匹配 [GET] "/recipes/1/like"我想要一个 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40513600/
我正在使用来自 chef 的软件包开发自定义 Recipe 。 我在 recipes 文件夹下创建了一个名为 apache.rb 的文件。 然后我通过 berks 上传了菜谱,并在一个节点上用 rec
I like to create a single Openrewrite migration jar that includes custom recipes and rewrite.yml
我正在尝试对一个模型进行 k 折交叉验证,该模型根据卫星图像预测树种断面积比例的联合分布。这需要使用 DiricihletReg::DirichReg() 函数,这反过来又需要使用 Dirichlet
在一本 Recipe 中,我有一个图书馆( client_helper.rb )。在其中定义了一个模块。模块名称为 客户 helper .这是模块代码。 module Client_helper #
我的 nginx Recipe 中有两个 Chef Recipe 。一个名为 default.rb,另一个名为 sites.rb。当我用 运行网站 Recipe 时 RUN_LIST=recipe[n
我有 Recipe base 和 Recipe myapp base 有 2 个配方 - my_java 和 java_with_custom_stuff 在 java_with_custom_stu
所以我使用以下配方: include_recipe "build-essential" node_packages = value_for_platform( [ "debian", "ubunt
我正在尝试使用 Vagrant 创建我的第一个 Chef Recipe ,但在第一步就遇到了问题。我的 Recipe 的第一行是: include_recipe "apt" 但是当我尝试 vagran
我已经下载了 Recipe “chef-jira”,现在我正在尝试在 Ubuntu 12.04 上使用 chef-solo/vagrant 运行它。 经过大量的谷歌搜索和 stackoverflow
我们有一个测试环境,由一台服务器、一台客户端和另一台作为工作站的客户端组成。 我知道命令 # knife cookbook site install apache2 但是这个命令会产生错误,因为我什至
我使用knife solo 使用.chef/knife.rb 定义的自定义模板创建了一个新文件夹和一个带有默认食谱的食谱。我的问题是我应该使用什么命令让刀使用该模板而不是使用 cp 创建新食谱? 类似
我是 Chef 的初学者。任何人都可以告诉我是否有一种方法可以将 Cookbook 的 files/default 目录中的目录复制到其他位置。 例如我在 files/ 目录中有一个包含文件 a.tx
我有一本包含 2 个食谱的食谱。 属性/default.rb default['vpn']['crt'] = 'nocrt' 默认配方具有创建通用 crt 文件的文件资源 file 'cert' do
我的情况是我有三本 Recipe ,每本都有一个写入/etc/hosts 文件的模板资源。 与其覆盖,我想附加: 第一本 Recipe 创建/etc/hosts 文件并写入第 1、2、3 行。 第二本
从我当前正在执行的食谱中,我想访问它在我的执行机器上的“当前”位置。 我需要它来访问它的缓存目录结构。 我有一种感觉,它位于“node[]”内的某个地方,但我根本找不到有关其结构的任何文档。 有什么建
z3c.recipe.scripts 和 zc.recipe.egg 似乎都在积极开发中。 z3c.recipe.scripts 描述为: The script recipe installs egg
我对 ModelMommy 有一段时间的烦恼,但我不知道如何正确地做到这一点。 让我们假设一个简单的关系: class Organization(models.Model): label =
我将一个 zip 文件放入 Recipe 中,然后将其上传到服务器后,我发现了这个错误。有人可以建议我解决此错误的正确解决方案吗... ERROR: Failed to upload ~/chef-r
我第一次使用 Chef,试图了解 Recipe 和 Recipe 。 我在配置我目前在我的角色文件中执行的标准 php 说明书后收到错误“mysql::client”失败: run_list( "
Glpk 需要使用configure make install 命令构建。所以我使用 zc.recipe.cmmi 配方来构建 glpk 包。它在 bin 目录中生成 glpsol 命令。我需要能够在
我是一名优秀的程序员,十分优秀!