小编sim*_*imo的帖子

Capybara和Rails,为什么has_link?总是返回false?

我想用has_link测试?在我的规范测试中,这是我的测试:

page.has_link?('next_page', {}).should == true
Run Code Online (Sandbox Code Playgroud)

但是,测试总是失败,尽管存在id为'next_page'剂量的链接!奇怪的是,has_content总是工作正常,这是我实现它的方式:

page.should have_content("some text")
Run Code Online (Sandbox Code Playgroud)

你能帮我吗 ?我在这里缺少什么?

编辑

以下是页面中的结果链接:

<a id="next_page" href="javascript: void(0)" onclick="javascript: void(0)" style="color: #888888">Next</a>
Run Code Online (Sandbox Code Playgroud)

rspec capybara ruby-on-rails-3

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

rails 3,为什么我不能在ubuntu上使用命令行?

我在Ubuntu 11.10上运行RubyMine 4,RubyMine中的每一件事情都很好,我可以运行服务器,开发等等.但是,当我需要在命令行上工作时,我什么都做不了..

我cd到我的app目录,然后我试着:

$ rails s
Run Code Online (Sandbox Code Playgroud)

我明白了:

The program 'rails' is currently not installed.  You can install it by typing:
sudo apt-get install rails
Run Code Online (Sandbox Code Playgroud)

这很奇怪,为什么我没有安装它,而我可以在RubyMine IDE中正常工作!

我需要使用命令行卸载gem,发现我不能使用命令行,因为它应该...

sam@ubuntu:~/Documents/RoR/course_builder$ gem uninstall 'capybara-firebug'
ERROR:  While executing gem ... (Gem::InstallError)
    cannot uninstall, check `gem list -d capybara-firebug`
Run Code Online (Sandbox Code Playgroud)

$ gem list -d 会给我:

*** LOCAL GEMS ***
Run Code Online (Sandbox Code Playgroud)

那里没有宝石..

如果我输入:

$ bundle install
Run Code Online (Sandbox Code Playgroud)

我明白了:

/usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8:in `require': no such file to load -- rubygems (LoadError)
    from /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8
    from /usr/lib/ruby/vendor_ruby/bundler.rb:11:in `require'
    from /usr/lib/ruby/vendor_ruby/bundler.rb:11
    from /usr/bin/bundle:4:in `require' …
Run Code Online (Sandbox Code Playgroud)

gem rubygems rubymine ruby-on-rails-3 ubuntu-11.10

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

AWS CodeDeploy?

我的应用程序是使用elastic-beanstalkaws服务创建的,是否需要使用AWS CodeDeploy服务来部署我的应用程序?

目前我只做:

eb deploy myApp
Run Code Online (Sandbox Code Playgroud)

然后,不使用AWS CodeDeploy部署新的应用程序版本。所以,我做错什么了吗?

amazon-web-services amazon-elastic-beanstalk aws-code-deploy

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

正确注入AuthManager?

我正在使用jwt-auth库,该库使用类型提示注入AuthManager:

use Illuminate\Auth\AuthManager;
class Basic extends Authorization
{

public function __construct(AuthManager $auth, $identifier = 'email')
    {
        $this->auth = $auth;
        $this->identifier = $identifier;
    }
Run Code Online (Sandbox Code Playgroud)

问题是,如果我使用了中间件jwt.auth:

app('Dingo\Api\Routing\Router')->version('v1', ['middleware' => ['jwt.auth'] , 'prefix' => 'api', 'providers' => ['jwt']], function ($api) {
    $api->get('protected', function () {

       $token = JWTAuth::getToken();
       return $token;
    });
});
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

{"message":"Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\\Auth\\AuthManager","status_code":500,"debug":{"line":839,"file":"\/share\/vendor\/illuminate\/container\/Container.php","class":"Illuminate\\Contracts\\Container\\BindingResolutionException"
Run Code Online (Sandbox Code Playgroud)

因此,问题是,如何正确注入AuthManager?为什么$ app无法解析?

laravel lumen

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

如何检测当前主题?

我将在哪里存储主题 ID?

至于插座,我可以使用:

def join("topic:" <> topic_id, _params, socket) do
    ...
    socket= assign(socket, :topic_id, topic_id)
    {:ok, socket}
end
Run Code Online (Sandbox Code Playgroud)

那是在套接字范围内,但我的用户可以同时加入多个主题,这意味着每次加入新主题时,上面的代码都会覆盖 topic_id,是真的吗?

如果我想知道哪个主题 ID 在handle_in?

例如:

def handle_in("new_message", params, socket) do

    # what is the active topic id here?

end
Run Code Online (Sandbox Code Playgroud)

我认为:

def handle_in("new_message:" <> topic_id, params, socket) do

    # now, I know that topic_id is the active topic

end
Run Code Online (Sandbox Code Playgroud)

有没有另一种方法可以做到这一点?或者这是怎么做的?

phoenix-framework phoenix-channels

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

关于 Task.Supervisor.async_stream_nolink 的示例?

尝试应用Task.Supervisor.async_stream_nolink进行少量测试,但不起作用。

这是我的实现:

defmodule MySupervisor do
    use Supervisor

    def start_link do
        Supervisor.start_link(__MODULE__, [])
    end

    def init([]) do
        children= [
            worker(Basic, [])
        ]

        supervise(children, strategy: :one_for_one)
    end
end

defmodule Basic do
    use GenServer

    def start_link do
        GenServer.start_link(__MODULE__, [], name: __MODULE__)
    end
end


strings = ["long string", "longer string", "there are many of these"]


stream = Task.Supervisor.async_stream_nolink(MySupervisor, strings, fn text -> text |> String.codepoints |> Enum.count end)


Enum.reduce(stream, 0, fn {:ok, num}, acc -> num + acc end) |> IO.puts
Run Code Online (Sandbox Code Playgroud)

但是,我得到了错误: …

elixir

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

为什么ListView没有虚拟化我的用户控件?

我试图在ListView中虚拟化我的用户控件,如下所示:

 <ListView VirtualizingStackPanel.IsVirtualizing="True"
                        VirtualizingStackPanel.CleanUpVirtualizedItem="stackPanel1_CleanUpVirtualizedItem"
                        VirtualizingStackPanel.VirtualizationMode="Standard"
                        Height="239" HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Top" Width="133" >              

                <ListView.Items>
                    <me:UserControl1 Backg="Green" />
                    <me:UserControl1 Backg="Blue" />
                    <me:UserControl1 Backg="Black" />
                    <me:UserControl1 Backg="Red" />
                    <me:UserControl1 Backg="Green" />
                    <me:UserControl1 Backg="Blue" />
                    <me:UserControl1 Backg="Black" />
                    <me:UserControl1 Backg="Red" />
                    <me:UserControl1 Backg="Blue" />
                    <me:UserControl1 Backg="Black" />
                     <me:UserControl1 Backg="Green" />
                    <me:UserControl1 Backg="Green" />
                </ListView.Items>
</ListView>
Run Code Online (Sandbox Code Playgroud)

但是,虚拟化不起作用,如果我使用Rectangle作为项目,虚拟化只是工作,如下所示:

  <ListView VirtualizingStackPanel.IsVirtualizing="True"
                        VirtualizingStackPanel.CleanUpVirtualizedItem="stackPanel1_CleanUpVirtualizedItem"
                        VirtualizingStackPanel.VirtualizationMode="Standard"
                        Height="239" HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Top" Width="133" >              

                <ListView.Items>
                    <Rectangle Width="20" Height="20" Fill="Gray" ></Rectangle>
                <Rectangle Width="20" Height="20" Fill="Green"></Rectangle>
                <Rectangle Width="20" Height="20" Fill="Orange"></Rectangle>
                <Rectangle Width="20" Height="20" Fill="Blue"></Rectangle>
                <Rectangle …
Run Code Online (Sandbox Code Playgroud)

wpf

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

Rails 3.1,将ERB重命名为HAML导致模板丢失

我决定开始使用HAML来加速开发,所以,我决定重命名我的视图:

new.html.erbnew.html.haml但是,似乎没有轨道更多的将它连接到控制器,下面是完整的错误信息:

模板丢失了

缺少模板测验/ new,application/new with {:handlers => [:erb,:builder,:coffee],:formats => [:html],:locale => [:en,:en]}.搜索:*"C:/ Users/Sam/RubymineProjects/hope/app/views"*"D:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/kaminari-0.12.4/app/views"*"D:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/devise-1.4.8/app/views"

这是新动作:

def new
    @quiz = Quiz.new

    respond_to do |format|
      format.html # new.html.erb
    #  format.json { render json: @quiz }
    end
  end
Run Code Online (Sandbox Code Playgroud)

那么,我该怎么办?

haml ruby-on-rails-3

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

我的Gemfile出了什么问题?

我试图捆绑安装,但这是我得到的:

/home/mywebsite/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:187:in `initialize': Malformed version number string = 1.0.3 (ArgumentError)
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/lockfile_parser.rb:104:in `new'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/lockfile_parser.rb:104:in `parse_spec'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/lockfile_parser.rb:71:in `parse_source'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/lockfile_parser.rb:30:in `block in initialize'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/lockfile_parser.rb:24:in `each'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/lockfile_parser.rb:24:in `initialize'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/definition.rb:44:in `new'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/definition.rb:44:in `initialize'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/dsl.rb:148:in `new'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/dsl.rb:148:in `to_definition'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/dsl.rb:8:in `evaluate'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/definition.rb:18:in `build'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler.rb:144:in `definition'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/cli.rb:228:in `install'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/vendor/thor/task.rb:27:in `run'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/vendor/thor.rb:275:in `dispatch'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/vendor/thor/base.rb:408:in `start'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/bin/bundle:14:in `block in <top (required)>'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/lib/bundler/friendly_errors.rb:4:in `with_friendly_errors'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/gems/bundler-1.2.3/bin/bundle:14:in `<top (required)>'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/bin/bundle:19:in `load'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@global/bin/bundle:19:in `<main>'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@mywebsiter/bin/ruby_noexec_wrapper:14:in `eval'
       /home/mywebsite/.rvm/gems/ruby-1.9.3-p362@mywebsiter/bin/ruby_noexec_wrapper:14:in `<main>'
There was an error in your Gemfile, and Bundler cannot continue.
Run Code Online (Sandbox Code Playgroud)

编辑 这是我的Gemfile:

source …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails bundler gemfile ruby-on-rails-3.2

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

如何将函数传递给Enum.each?

我需要使用Enum.each将列表项传递给函数

ex:
users= [1, 2, 3, 4, 5]

#how to link the handler_user function in Enum.each?
users 
|> Enum.each handler_user

def handler_user user_id
end
Run Code Online (Sandbox Code Playgroud)

那么,我该怎么做这个链接呢?

elixir

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

为什么我得到**(EXIT)错误的返回值:: ok

我需要让GenServer监视器成为一项任务,因此,我这样做:

GenServer.call(server_pid, {:monitor_task, self()})
Run Code Online (Sandbox Code Playgroud)

在服务器中:

def handle_call({:monitor_task, task_pid}, _from, state) do
  ref = Process.monitor(task_pid)
  {:reply, ref, state}
end
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误:

** (stop) exited in: GenServer.call(#PID<0.768.0>, {:monitor_task, #PID<0.849.0>}, 5000)
    ** (EXIT) bad return value: :ok
Run Code Online (Sandbox Code Playgroud)

任何的想法?

elixir

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