在rails中达到控制器操作后获取404错误后发布数据

时间:2015-07-19 06:02:48

标签: ruby-on-rails ruby redmine redmine-plugins

我一直在尝试将数据发布到RAILS应用程序开发中的控制器操作。当我通过表单发布数据时,POST数据到达routes.rb中定义的特定控制器操作。但它给出了404错误。

这是代码:

控制器 - >

class UserActivityController < ApplicationController
unloadable

def index
   #Defining form
   @userActivity = UserActivity.new
end

def create
    puts "Helloo"
    @user_activity = UserActivity.new
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @user_activity }
    end
end

routes.rb - &gt;

match 'timesheet/create' => 'userActivity#create', :via => :post, :as=>:create

我尝试了

post 'timesheet/create', :to => 'userActivity#create'

表格 - &gt;

<%= form_for @userActivity,:url => { :controller=>"userActivity",:action => "create" }, :remote => true do |task| %>
[.....]
<% end %>

错误:

Started POST "/timesheet/create" for 127.0.0.1 at 2015-07-19 11:12:58 +0530
Processing by UserActivityController#create as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"qsqRIGH8caCz4I25m1sFKviELHEYOWNUsiLYNnc1kP8=", "date"=>"2015-07-19", "project"=>"", "task"=>{"detail"=>""}, "time"=>{"start(5i)"=>"", "end(5i)"=>""}, "issue"=>"", "commit"=>"Create"}
Helloo
Current user: XXX (id=XX)
Missing template, responding with 404
  Rendered common/error.html.erb (0.6ms)
Completed 404 Not Found in 7ms (Views: 1.8ms | ActiveRecord: 0.0ms)

请帮我解决这个问题!

1 个答案:

答案 0 :(得分:1)

创建parameters的{​​{1}}在哪里?您可以在日志中看到UserActivityuser。此外,在提交发布方法后,您应使用ID(XX)或创建redirect_to文件以create.js回复。