小编Jul*_*ray的帖子

在行动不起作用之前Rails跳过

我对skip_before动作有一些问题:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  before_action :require_login
  before_action :inc_cookies

  def inc_cookies
    if cookies[:token] != nil
      @name = cookies[:name]
      @surname = cookies[:surname]
      @user_roomate = cookies[:roomate]
    end
  end

  def require_login
    if cookies[:token] == nil
      puts "No token"
      redirect_to '/'
    end


  end
end
Run Code Online (Sandbox Code Playgroud)

和我的另一个控制器:

class UsersController < ApplicationController
 skip_before_action :require_login, :except => [:landing, :connect, :create]
end
Run Code Online (Sandbox Code Playgroud)

我不知道为什么,但是当我在根(中:从UsersController登陆行动),Rails的尝试在require_login通过......我misundertood一些与此过滤器,还是我什么了吗?

谢谢你的帮助!

ruby-on-rails

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

从Meteor中的事件中检索自定义数据属性的最佳方法?

我想知道从事件对象中使用Meteor检索自定义数据HTML属性值的最佳方法是什么?

例如:

articles.html

   <template name="createArticle">
    <form class="new-article">
        <input type="text" name="title" placeholder="New title"/>
        <input type="text" name="content" placeholder="New content" />
        <!-- list categ -->
      <label>Category
        <select id="categ-list" name="categ">
          {{#each categories}}
            <option value="{{name}}" data-id={{_id}}>{{name}}</option>
          {{/each}}
        </select>
      </label>
        <input type ="submit" value= "Create" class="button">
    </form>
</template>
Run Code Online (Sandbox Code Playgroud)

articles.js

   Template.createArticle.events({
  "submit .new-article": function(event){
    var title = event.target.title.value;
    var content = event.target.content.value;
    var categName = event.target.categ.value;
    var categId = event.target.categ.data('id'); // HERE
    console.log("test " + categId);
    Meteor.call("addArticle", title, content, categId, categName);
    event.target.title.value = "";
    event.target.content.value = ""; …
Run Code Online (Sandbox Code Playgroud)

javascript meteor

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

如何在Rails中包含自定义异常?

我不太清楚Rails如何包含(或不?)app目录中的某些文件.

例如,我创建了一个新的目录app/exceptions来创建我自己的异常.现在,从帮助文件中,我想提出一个异常.

我想在这个助手中加入一些东西吗?

助手:助手/ communications_helper.rb

//should I include something or it's suppose to be autoloaded?
module CommunicationsHelper
 begin.
 .
 . 
 .
  raise ParamsException, "My exception is lauch!"
 rescue StandardError => e
...
 end
end
Run Code Online (Sandbox Code Playgroud)

例外:exceptions/params_exception.rb

class ParamsException < StandardError
  def initialize(object, operation)
    puts "Dans paramsException"
  end

end
Run Code Online (Sandbox Code Playgroud)

没有什么具体来自我在产出中的提升......

谢谢!

编辑:谢谢大家,你的两个答案以不同的方式有所帮助.我没有像你说的那样提高异常,但我也要忘记更新我的config.rb.所以我现在:

rescue StandardError => e
  raise ParamsError.new("truc", "truc")
Run Code Online (Sandbox Code Playgroud)

其他问题,你知道我在哪里能加注吗?因为我已经陷入困境,所以我很少迷路......

ruby ruby-on-rails

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

标签 统计

ruby-on-rails ×2

javascript ×1

meteor ×1

ruby ×1