I have a cucumber step
When /^I go to the Add Suggestions form$/ do
visit new_manage_suggestions_path
end
and a route
namespace "manage" do
resource :suggestions
end
rake routes outputs
manage_suggestions POST /manage suggestions(.:format) manage/suggestions#create
When I run cucumber I get
undefined method `suggestions_path' for #<#<Class:0x000000064a4768>:0x000000064accd8> (ActionView::Template::Error)
Why is cucumber trying that path?
The new_manage_suggestions_path works fine in my app, I have a link that uses it and that is working fine.
In your routes definition, in order to have your app generate the correct routes, you need to switch from the singular resource to plural resources since you could potentially have multiple suggestions.
namespace "manage" do
resources :suggestions
end
More details can be found in the Rails documentation on singular resources, where you can see that the singular version does not include the namespace in its path names.
Related
How can helpers be accessed from middleman console? Answer for both 3.x and 4.x would be helpful if it's not the same object path.
I couldn't find any documentation on this, so settled for the following work around:
Here's my helper
module PageHelpers
def thing
"THING!"
end
end
Call the helper method on an instance of a class that includes it:
$ bundle exec middleman console
irb...> (class Thing; include PageHelpers; end).new.thing
=> "THING!"
In a rails project, i add a feature file and step definition try to use capybara+selenium to load an external url,but it can not work? it has no any browser loading behavior,and from the console, it did not request the external url 'http://baidu.com' but 'http://localhost:3000' why, how can check for me,thanks very much!
**env.rb**
require 'cucumber/rails'
require 'capybara/rails'
require 'capybara/cucumber'
require 'selenium/client'
Capybara.current_driver = :selenium
Capybara.default_selector = :css
**setp_definition:**
When /^i visit baidu$/ do
visit('http://www.baidu.com/')
end
Then /^you should see Baidu$/ do
page.should have_content('Baidu')
end
****the infor on the console:****
[31m expected there to be text "Baidu" in "Browse the documentation Rails
Guides Rails API Ruby core Ruby standard library Welcome aboard You鈥檙e riding
Ruby on Rails! About your application鈥檚 environment Getting started Here鈥檚 h
ow to get rolling: Use rails generate to create your models and controllers To s
ee all available options, run it without parameters. Set up a default route and
remove public/index.html Routes are set up in config/routes.rb. Create your data
base Run rake db:create to create your database. If you're not using SQLite (the
default), edit config/database.yml
with your username and password." (RSpec::Ex
pectations::ExpectationNotMetError)[0m.
I want to do simple request specs in my Rails 3.1 application with Capybara. The standard cases all work as expected, but when I want to test CSS generated by the asset pipeline, I receive the following error:
Failure/Error: visit '/assets/main.css'
ActionController::RoutingError:
No route matches [GET] "/assets/main.css"
I think the problem is that the test environment does not provide a complete server and so also no Sprockets middleware delivering the assets.
Is there a solution to this problem?
EDIT: Now possible!
We updated to Rails 3.2.12 and Capybara 2.0.2, now the assets are also available in the feature specs.
The Phusion guys blogged about a possibility to render an asset to a string:
MyApp::Application.assets.find_asset('main.css').body
You can also use this in tests. The solution is not ideal and/since Capybara isn't involved anymore, but it helps in my specific case to validate CSS. Better approaches are welcome!
In the mail app's rails console (irb), how to access engine's models.
update: Say "team" is my main app and "team_page" is the engine. "team_page" is required in main app in the gemfile through 'gem => "team_page", :path => "local/path/to/team_page"'.
when I go to team's rails console, I couldn't access team_page's models.
First you must know the module's name. To help with that, you can run a
bundle show team_page
to find its directory and explore over there (probably under lib/team_page.rb) until
you see the following definition:
module TeamPage
# ...
end
Let's say that the module is called TeamPage. Then just prepend double colon to its name like this:
::TeamPage::SomeModel.some_method
I have a rails application I would like to use for multiple sites, each with different designs.
I would like to change the rails installation /public directory to something else (dynamically eventually). However, I have run into a problem (bug?) changing directories...
In my application.rb file I change the paths.public path to something other than "public" (let's say "site_one"). Here is the code:
puts paths.public.paths
paths.public = "site_one"
puts paths.public.paths
The two "puts" commands are for debugging. Now run "rails s" and you will see:
/home/macklin/app/public
/home/macklin/app/site_one
This verifies the path is changed correctly. However, shortly afterward, rails throws the following error (let me know if you need the full trace):
Exiting
/usr/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/paths.rb:16:in `method_missing': undefined method `javascripts' for #<Rails::Paths::Path:0x7f422bd76f58> (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.3/lib/action_controller/railtie.rb:47
My guess is it cannot find the javascripts directory even though it is clearly sitting in the "site_one" folder.
Does anyone know why I am getting this?
I know this question is pretty old, but I think I found an answer for this in Rails 4.2.
You just simply have to put this line in your config/application.rb:
middleware.use ::ActionDispatch::Static, "#{Rails.root}/another_public_folder_name", index: 'index', headers: config.static_cache_control
This makes all files in /another_public_folder_name to be served by Rails.
This is the way Rails use to setup the standard /public folder. I found it checking the sources:
https://github.com/rails/rails/blob/52ce6ece8c8f74064bb64e0a0b1ddd83092718e1/railties/lib/rails/application/default_middleware_stack.rb#L24
Duh. Just add 2 more rules for stylesheets and javascripts (I guess they get wiped when you change the parent path)
paths.public.stylesheets = "site_one/stylesheets"
paths.public.javascripts = "site_one/javascripts"