【发布时间】:2016-10-11 11:43:15
【问题描述】:
我是 ruby on rails 的新手, 我想制作一个简单的文本字段,您可以在其中更改内容并将其存储在数据库中。但是提交按钮不会调用 Profiles 控制器。 "Foo" 永远不会被提出。
routes.rb:
Rails.application.routes.draw do
devise_for :users
get 'welcome/user'
resources :profiles
end
user.html.erb:
...
<%@profile=Profile.find_by user_id: current_user.id%>
<%= form_for (@profile) do |f| %>
<%= f.text_field :name%>
<%= f.submit%>
<% end %>
profiles_controller.rb:
class ProfilesController < ActionController::Base
def update
raise "foo"
end
end
【问题讨论】:
-
查看你的服务器,看看调用了什么动作
-
<%@profile=Profile.find_by user_id: current_user.id%>- 那东西肯定属于控制器。 -
可能,您需要向
form_forhelper 提供操作。 -
如果我把它改成这个
<%= form_for (@profile) , :url => url_for(:action => "update", :controller => "profiles", :profile_id => @profile.id) do |f| %>然后没有路由匹配{:action=>"update", :controller=>"profiles", :profile_id=>3}
标签: ruby-on-rails ruby controller submit call