【问题标题】:The action 'new_status' could not be found for TasksController找不到 TasksController 的操作“new_status”
【发布时间】:2019-01-17 13:04:09
【问题描述】:

我需要有关此问题的帮助。我有任务控制器

RESTful 动作和

private

def new_status
  @tasks.update!(active: params[:active])
  flash[:notice] = "Status update"
  redirect_to action: "index"
end

有路线

resources :tasks do
    get :new_status, on: :member
  end

但我无法通过此链接更改数据库中的活动值

 <%=link_to "send data", new_status_task_path(task.id, :active => false) %>

在 *.html.erb 中

<% @tasks.where(active: true).order(:priority).each do |task| %>
          <li class="task">
            <%= link_to task.title, task, class: "task-title text-dark" %>
            <span class="task-btn">
                <%=link_to "send data", new_status_task_path(task.id, :active => false) %>
                <%= link_to '', '', class: "fas fa-bell text-dark icon" %>
                <%= link_to '', edit_task_path(task), class:"fas fa-cogs text-dark mx-2 icon" %>
                <%= link_to '', task, method: :delete, data: { confirm: 'Are you sure?' }, class:"far fa-trash-alt text-dark icon" %>
            </span>
          </li>
      <% end %>

【问题讨论】:

    标签: ruby-on-rails ruby controller action


    【解决方案1】:

    控制器操作必须是公开的。将new_status 的定义移到private 声明之前。

    def new_status
      @tasks.update!(active: params[:active])
      flash[:notice] = "Status update"
      redirect_to action: "index"
    end
    
    private
    
    # rest of the controller
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 2011-10-01
      相关资源
      最近更新 更多