标签: actioncontroller

ActionController::RoutingError: 没有路由匹配 [POST]

    require 'test_helper'

     class MyTest < ActionController::IntegrationTest

      test "view posts from login page" do
      visit("/logins/new")
      find_field('Username').set('abode')
      find_field('Password').set('efghi')
      click_link_or_button('Login')
      assert page.has_content?('Signed in!')
      end

      test "go to new user page" do
        visit("/logins/new")
        click_link("New user?")
        assert (current_path == "/users/new")
      end

    end

   Error:
test_view_posts_from_login_page(MyTest):
ActionController::RoutingError: No route matches [POST] "/logins/new"
    test/integration/view_posts_test.rb:12:in `block in <class:MyTest>'
Run Code Online (Sandbox Code Playgroud)

它显示第 12 行的错误。按钮“登录”或 /logins/new 路径是否有问题?第二个测试通过了所以路径应该是正确的?我究竟做错了什么?

谢谢!

integration-testing ruby-on-rails actioncontroller capybara

1
推荐指数
1
解决办法
2万
查看次数

对象引用未设置为对象错误MVC3的实例

我有一个ajax帖子,它给出了用户输入表单的值.

在我的数据库中,我有两个正在使用的entites,我首先使用模型.但是,在尝试执行此操作时,我得到"对象引用未设置为对象的实例"错误:

goalCardQuestionAnswer.SelectedQuestion.Id = selectedQuestionViewModel.QuestionID;

这是我的控制器帖子:

    [HttpPost]
    public bool AnswerForm(SelectedQuestionViewModel selectedQuestionViewModel)
    {
        if (ModelState.IsValid)
        {
        var goalCardQuestionAnswer = new GoalCardQuestionAnswer();

        goalCardQuestionAnswer.SelectedQuestion.Id = selectedQuestionViewModel.QuestionID;
        goalCardQuestionAnswer.Comment = selectedQuestionViewModel.Comment;
        goalCardQuestionAnswer.Grade = selectedQuestionViewModel.Grade;

        answerNKIRepository.SaveQuestionAnswer(goalCardQuestionAnswer);
        answerNKIRepository.Save();

        }
Run Code Online (Sandbox Code Playgroud)

我的SelectedQuestionViewModel:

   public class SelectedQuestionViewModel
{

    public int? Grade { get; set; }
    public string Comment { get; set; }
    public string SelectedQuestionText { get; set; }
    public int QuestionID { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

我的数据库模型

在此输入图像描述

asp.net-mvc entity-framework actioncontroller asp.net-mvc-3

1
推荐指数
1
解决办法
1916
查看次数

在 ruby​​ 中,如何选择第一个哈希条目,其键是数组的第一个匹配条目?

目标类似于以下代码:

h={ i:4, j:3, k:2}
a=[ :f, :g, :j, :z, :i]
h.get_first_matching_in(a)
=> :j
h.select first_from(a)
=> :j
Run Code Online (Sandbox Code Playgroud)

什么应该进去.get_first_matching_infirst_from

arrays hash select ruby-on-rails actioncontroller

1
推荐指数
1
解决办法
1175
查看次数

Rails:将params hash传递给模型

我有一个用户到用户的消息系统.我正在尝试将一组用户ID传递给ConversationUser(连接表)模型,然后conversation_users从每个人创建多个user.id.这两个领域ConversationUserconversation_iduser_id.我能够初始化单个会话用户,因为新conversation_id的传递给模型,但由于某种原因,用户ID的哈希不会到达我的模型.我得到了一个Validation failed: User can't be blank

我的对话/捕获user_ids的新视图:

<%= check_box_tag "conversation_user[recipient][]", user.id %> <%= user.name %><br />
Run Code Online (Sandbox Code Playgroud)

我知道这是有效的,因为我收到的部分短信是:

"conversation_user"=>{"recipient"=>["9", "10"]}
Run Code Online (Sandbox Code Playgroud)

我的Rails 4控制器的基本要点和强大的参数:

class ConversationsController < ApplicationController
  def new
    @user = User.find(params[:user_id])
    @conversation = @user.conversation_users.build
    @conversation.build_conversation.messages.build
  end

  def create
    @conv = Conversation.create!
    @conversation = @conv.conversation_users.create!(conversation_user_params)
  end

  def conversation_user_params
    params.require(:conversation_user).permit(recipient: [])
  end
Run Code Online (Sandbox Code Playgroud)

我的ConversationUser模型的基本要点:

class ConversationUser < ActiveRecord::Base
  attr_accessor :recipient

  before_create :acquire_conversation

  validates :user_id, :conversation_id, presence: true 

  def acquire_conversation …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails actioncontroller strong-parameters

0
推荐指数
1
解决办法
8121
查看次数

我正在获得没有路由匹配[DELETE]自定义操作和轨道上的ruby中的路由

我有一个显示页面,列出了我的数据库中的所有对象.我有一个删除链接,将该对象的ID发送到关联控制器中的destroy方法,然后我可以轻松删除该对象并重定向回显示页面.

在同一个展示页面上,我在每个相应的对象旁边都有一组内嵌图像.每个图像实际上都是一个链接(首先除了不应该删除).当我单击特定图像时,我将对象的ID加上对象的列名作为字符串发送到名为destroyImage的新自定义方法.

我在我的控制器中创建了这个方法:

  def destroyImage
    garment = Parse::Query.new("Garments").eq("objectId", params[:id]).get.first
    garment[params[:imageToDelete]] = nil
    if garment.parse_delete
      flash[:success] = "Image successfully deleted!"
      redirect_to adminpanel_path
    else
      flash[:error] = "Image not deleted, try again!"
      render "show"
    end
  end
Run Code Online (Sandbox Code Playgroud)

在我看来:

   <td class= "images">
     <div id="deleteText"><%= "Click on image to delete." %></div>
     <%= image_tag garment["image"].url if garment["image"] %> 
     <%= link_to image_tag(garment["image2"].url), destroyImage_adminpanel_path(:id => garment["objectId"], :imageToDelete => "image2"), :method => 'delete' if garment["image2"] %>
     <%= link_to image_tag(garment["image3"].url), destroyImage_adminpanel_path(:id => garment["objectId"], :imageToDelete => "image3"), :method => 'delete' if garment["image3"] …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails link-to actioncontroller ruby-on-rails-4

0
推荐指数
1
解决办法
1341
查看次数

Rails 5-在更新时手动将属性添加到控制器中的参数

我试图在完成表单后手动向控制器中的参数添加其他属性。参数似乎包裹在中,这似乎阻止了我更改参数。

控制器:

class ActualsController < SignedInController
...
 def update
   respond_to do |format|
   facesheet = actual_params[:facesheet]

   #trying to manually add attribute
   actual_params.merge(:file_name => 'ted.png')
   new_params = actual_params.except(:facesheet)

      if @actual.update(new_params)
        format.html { redirect_to action: 'show', id:@actual.id, notice: 'Actual was successfully updated.' }
        format.json { render :show, status: :ok, location: @actual }
      else
        format.html { render :edit }
        format.json { render json: @actual.errors, status: :unprocessable_entity }
      end

   end
 end
...
end
Run Code Online (Sandbox Code Playgroud)

控制台中的“ new_params”

<ActionController::Parameters {"encounter_type_id"=>"1", "physician_id"=>"669", "insurance_id"=>"1182", "time_start"=>"05:00", "time_end"=>"07:00", "date_start"=>"2017-08-02", "date_end"=>"2017-08-02", "facility_id"=>"1", "med_rec_num"=>"1244", …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails actioncontroller ruby-on-rails-5

0
推荐指数
2
解决办法
4306
查看次数