Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActionController::RoutingError(没有与[PUT]“welcome”匹配的路由):_Ruby On Rails_Ajax_Routes - Fatal编程技术网

Ruby on rails ActionController::RoutingError(没有与[PUT]“welcome”匹配的路由):

Ruby on rails ActionController::RoutingError(没有与[PUT]“welcome”匹配的路由):,ruby-on-rails,ajax,routes,Ruby On Rails,Ajax,Routes,我想要下一件事: 单击按钮时,我想打印欢迎控制器的参数[:id] 这是我的java脚本代码: $(".btn_skip").click(function() { $.ajax({ url: '/welcome', type: 'PUT', data: {show_msg: $("#mycheckbox").is(":checked")} }); }); $("#submit").click(function() { user_

我想要下一件事: 单击按钮时,我想打印
欢迎控制器的
参数[:id]

这是我的java脚本代码:

$(".btn_skip").click(function() {
    $.ajax({
        url: '/welcome',
        type: 'PUT',
        data: {show_msg: $("#mycheckbox").is(":checked")}
    });
});
$("#submit").click(function() {
  user_id = $('#current_user').val();
  $.ajax({
    ## the url is the controller
    url: '/welcome' + user_id,
    type: 'PUT',
    data: {show_msg: $("#mycheckbox").is(":checked")}
  });
});
这是我的
欢迎\u控制器。rb

class WelcomeController < ApplicationController
def update
    @user = User.find(params[:id])
    puts params[:id]
    end
end
routes.rb:

resources :welcome
rake路由

welcome_index GET    /welcome(.:format)          welcome#index
              POST   /welcome(.:format)          welcome#create
new_welcome   GET    /welcome/new(.:format)      welcome#new
edit_welcome  GET    /welcome/:id/edit(.:format) welcome#edit
welcome       GET    /welcome/:id(.:format)      welcome#show
              PUT    /welcome/:id(.:format)      welcome#update
              DELETE /welcome/:id(.:format)      welcome#destroy
也许,我应该在
url:'/welcome'
中传递id吗

如果是的话,我怎样才能得到身份证?可能是:url:'/welcome/#{:id}'


感谢您的帮助

如果使用html.erb模板生成Javascript,则使用内置url生成器。e、 g

这是我的Index.html.erb

<% @device_layouts.each do |device_layout| %>
  <tr>
    <td><%= link_to 'Show', device_layout %></td>
    <td><%= link_to 'Edit', edit_device_layout_path(device_layout) %></td>
    <td><%= link_to 'Destroy', device_layout, confirm: 'Are you sure?', method: :delete %></td>
  </tr>
<% end %>

我建议您使用rails表单助手,而不是普通的html。无论如何,这是您的选择,在当前的实现中,您可以向表单添加一个隐藏字段。我假设您希望将当前用户的id传递给更新操作

<input type="hidden" id="current_user" value="<%= current_user.id %>" />

就这样!它将获取用户id并自动传递到更新操作。:)

是的,你需要把身份证传过去。您可以通过
获取id,假设您正在使用erb模板进行Javascript视图,其中@something是您传递给/welcome view file进行渲染的对象。好的,谢谢,但是我如何传递它呢?类似于:'/welcome/#{:id}'?是否在欢迎页面上检索对象?您可以在index.html页面中获取id。我在board的控制器中有一个div类,我在弹出窗口中显示它,通过以下行:$(“#欢迎对话框”)。lightbox_me({centered:true,onLoad:function(){//alert(“页面已加载”);});所以我不知道如何将id发送给欢迎控制员这是您上一个问题的后续;)
<input type="hidden" id="current_user" value="<%= current_user.id %>" />
$("#submit").click(function() {
  user_id = $('#current_user').val();
  $.ajax({
    ## the url is the controller
    url: '/welcome' + user_id,
    type: 'PUT',
    data: {show_msg: $("#mycheckbox").is(":checked")}
  });
});