I come from this post:
Rails using puma, change localhost:3000 to localhost:3000/example
I have fixed this issue, but now I receive "Method not allowed" when I do a post request. I have been reading and tried this solution:
Post returns 405 method not allowed
I know where is the problem: If I put in application.rb lines 1- and 2-, all assets are shown correctly and post methods aren't doing it. If I comment these lines, methods works but assets don't.
Application.rb:
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
config.exceptions_app = ->(env) { ExceptionController.action(:show).call(env) }
config.action_dispatch.rescue_responses["BadTaste"] = :bad_request
1- config.action_controller.asset_host = "https://www.sevilla.org"
2- config.assets.prefix = '/autorizaciones-movilidad'
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
Routes:
Rails.application.routes.draw do
#resources :assets, path: '/autorizaciones-movilidad'
scope "/autorizaciones-movilidad" do
get 'vehicles/new'
get 'vehicles/create'
...
get 'vehicles/update'
end
end
Controller structure:
Don't know how to solve it.
It is deployed with a proxy server (in localhost it was working ok)
Related
I'm pretty new to chef. I'm using it to provision a vagrant development environment using the apache2-windows cookbook, which inconveniently has very little by way of documentation. I have managed to get it to install, and even play nicely with opscodes php cookbook, but I'm struggling to get it to set up a vhost.
So far I have added the vhosts 'extra' to /attributes/default.rb like so:
default['apache']['windows']['extras'] = ["vhosts"]
That successfully adds a 'vhosts.d' directory to apache root, includes httpd-vhosts.conf in httpd.conf, and adds an entry to httpd-vhosts.conf which includes *.conf in the 'vhosts.d' directory.
Unfortunately I can't quite figure out how to use the virtualhost resource provided with the recipe, which looks like it should be putting my vhosts into the 'vhosts.d' using the /templates/default/virtualhost.conf.erb template.
I have added the following to /recipes/default.rb
virtualhost "mysite.localhost" do
server_aliases ["www.mysite.localhost"]
docroot "/vagrant"
action :create
end
but it fails, telling me 'No resource or method named 'virtualhost' for 'Chef::Recipe "default"'.
What am I missing? Is there something else I need to do to allow me to use the virtualhost resource in my recipe?
It's one of the caveat with library cookbooks/LWRP their names are derived from the cookbook name.
Doc is HERE
If apache2-windows is not in the runlist you have to define it with depends 'apache2-windows' in your cookbook metadata.rb.
But the main problem here is that the virtualhost resource will be named apache2_windows_virtualhost due to 2 things:
The resource is derived from the cookbook name, so it become cookbook_resource
Ruby does not allow - in classes names, so they are 'magically' converted to _ for resources calls.
tl;dr; use this
apache2_windows_virtualhost "mysite.localhost" do
server_aliases ["www.mysite.localhost"]
docroot "/vagrant"
action :create
end
I have several static erb pages being served up in a ruby rails 4 site via the high voltage gem:
get '/about' => 'high_voltage/pages#show', id: 'about'
get '/contact' => 'high_voltage/pages#show', id: 'contact', :protocol => "https"
get '/privacy' => 'high_voltage/pages#show', id: 'privacy'
This all works well and good, except that the /contact route doesn't redirect or force SSL on, it is happy with whatever protocol is used.
I host the site on engine yard, attempting to put :force_ssl only or variants in the route line resulted in failed deployments - high voltage uses a slightly different set of arguments than normal routes so I suspect there is a conflict somewhere.
Anyone use highvoltage and SSL with rails 4 for select static pages (not the whole site)? Example routes line please.
You can achieve this by overriding the HighVoltage#PagesController see the override section of the documentation.
It might look something like this:
class PagesController < ApplicationController
include HighVoltage::StaticPage
before_filter :ensure_secure_page
private
def ensure_secure_page
if params[:id] == 'contact'
# check to make sure SSL is being use. Redirect to secure page if not.
end
end
end
Next disable the routes that HighVoltage provides:
# config/initializers/high_voltage.rb
HighVoltage.routes = false
Then in your application's routes file you'll need to set up a new route:
# config/routes.rb
get "/pages/*id" => 'pages#show', as: :page, format: false
I am using devise-invitable gem in my application. If the user exists in the application and he clicks accept invitation link he should be redirected to sign in page other if new user clicks the link he should be redirected to sign up page. I am not getting how I can override the after_accept_path_for method for that...Where and how can I override this method, can some one please help me in this?
Following https://github.com/scambra/devise_invitable/ link
I think you might want to re-read the documentation, your question is answered in the docs, just not all in one place.
Here are the two sections that concern your question:
https://github.com/scambra/devise_invitable#configuring-controllers
https://github.com/scambra/devise_invitable#integration-in-a-rails-application
Basically you're going to add a controller for invitations and add routing information for that controller (app/controllers/users/invitations_controller.rb) like this:
class Users::InvitationsController < Devise::InvitationsController
def after_accept_path_for
"some path you define"
end
end
Then you'll change your routes.rb to tell devise to use your invitations controller like:
devise_for :users, :controllers => { :invitations => 'users/invitations' }
With devise 2.1.2 and devise_invitable 1.1.8, the page you end up on after setting password from the invitation link depends on what you set the root path for your devise resource in the config/routes.rb so #trh's answer doesn't work with this version (I tried and failed). From the devise code comments:
# The default url to be used after signing in. This is used by all Devise
# controllers and you can overwrite it in your ApplicationController to
# provide a custom hook for a custom resource.
#
# By default, it first tries to find a valid resource_return_to key in the
# session, then it fallbacks to resource_root_path, otherwise it uses the
# root path. For a user scope, you can define the default url in
# the following way:
#
# map.user_root '/users', :controller => 'users' # creates user_root_path
#
# map.namespace :user do |user|
# user.root :controller => 'users' # creates user_root_path
# end
#
# If the resource root path is not defined, root_path is used. However,
# if this default is not enough, you can customize it, for example:
#
# def after_sign_in_path_for(resource)
# stored_location_for(resource) ||
# if resource.is_a?(User) && resource.can_publish?
# publisher_url
# else
# super
# end
# end
In my case, I had two different namespaces with one namespace called "portal" which I was using a "PortalUser" class for the user. For Rails 3.2, I simply declared this line in my routes.rb:
get "portal" => 'portal/dashboard#index', as: :portal_user_root
The important note is the naming, "portal_user_root" which is the underscored name of PortalUser class name. Simply setting this named route is all that's needed for your devise_invitable to redirect as desired.
I'm on a VPS. I created a new rails app with rails new rails_app -d mysql.
I'm running nginx with passenger. I'm running Rails 3.2.12 and Ruby 1.9.3. In my nginx.conf file I added the following to the server directive:
listen 80;
server_name www.mydomain.com;
passenger_enabled on;
root /home/mike/www/rails_app/public;
rails_env production;
When I point to www.mydomain.com I see Welcome aboard You’re riding Ruby on Rails!. When I click on About your application’s environment I get this error:
The page you were looking for doesn't exist.
When I check my production.log I see this error and don't know what to do with it:
ActionController::RoutingError (No route matches [GET] "/rails/info/properties")
I've been up all night and have read all SO issues similar to this but still I cannot resolve my issue. If I run this in development everything works fine.
EDIT
I found this explanation for a Rails 2.3.4 problem: The link fires off an AJAX request to rails/info/properties. The properties action is defined in the Rails::InfoController which lives in /rails/railties/builtin/rails_info/rails/info_controller.rb.
The route doesn't need to be explicitly defined because it conforms to the Rails default route of :controller/:action/:id (although there is no ID in this case and the controller lives within a Rails namespace.)
But I don't see info_controller.rb anywhere.
Ok I found this: config.consider_all_requests_local is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the Rails::Info controller will show the application runtime context in /rails/info/properties. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement local_request? in controllers to specify which requests should provide debugging information on errors.
but setting this to false does nothing.
EDIT 2
Ok, I'm an idiot. Found this somewhere: You're clicking the "About your application’s environment" link on the Rails default index.html page. This link only works in development environment, not in production.
And this entire night I thought my Rails app wasn't working. So I guess I'll give up and go to sleep.
You forgot to add passenger_base_uri:
server {
listen 80;
server_name domain.com;
charset utf-8;
root /www/domain.com/public_html;
passenger_enabled on;
passenger_base_uri /blog;
rails_spawn_method smart;
rails_env production;
}
Also check that passenger and rails work in the same environment (production or development).
For those who might encounter this problem in the future, first check your production logs in your server.
ssh into your server, ssh username#serverIP
Check the last 20 or so error messages tail -20 /home/username/appname/current/log/production.log
If it's a bug in your code (mine was returning an empty array due to an empty db), then fix that bug and run cap production deploy once again.
Repeat to check for more errors.
Same problem is also faced by me, but I found later wards due to permission, our application is not able to access the specific folder.
Try this command :
chmod -R 777 {name of your project folder}/
I am writing my first application in rails and here is what I did
C:\Personal\rails\demo>ruby -v
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
C:\Personal\rails\demo>rails -v
Rails 3.0.5
C:\Personal\rails\demo>rails generate model book
invoke active_record
create db/migrate/20110325190010_create_books.rb
create app/models/book.rb
invoke test_unit
create test/unit/book_test.rb
create test/fixtures/books.yml
C:\Personal\rails\demo>rake db:migrate
(in C:/Personal/rails/demo)
== CreateBooks: migrating ====================================================
-- create_table(:books)
-> 0.0000s
== CreateBooks: migrated (0.0000s) ===========================================
C:\Personal\rails\demo>rails generate controller admin
create app/controllers/admin_controller.rb
invoke erb
create app/views/admin
invoke test_unit
create test/functional/admin_controller_test.rb
invoke helper
create app/helpers/admin_helper.rb
invoke test_unit
create test/unit/helpers/admin_helper_test.rb
Then i edited the admin_controller.rb as follows:
class AdminController < ApplicationController
scaffold :book
end
Here is the routes.rb file
Demo::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end
However, when I go to http://localhost:3000/admin, I get a "No route matches "/admin"" error. I noticed that my routes.rb has only the commented lines. Did I do something wrong?
You have not added a route for admin, why are all your routes commented out.
if admin is a resource add this line
resources :admin
Also in your controller you will need an index method and index view file because http://localhost:3000/admin will take you there
Try removing the comment from this line:
match ':controller(/:action(/:id(.:format)))'
Note: This answer is for the case when above mentioned points are met yet you keep seeing this error. It was Rails 3.2 and Ruby 2.3.8
Problem definition:
I successfully logged in using admin creds. When page landed on /admin I saw No route matches [GET] "/admin" error page. I hit my head everywhere and used all my knowledge. Also, generated routes and grep but no admin route was published.
$ rake routes | grep admin
but only devise related admin routes were published. And then I read the warning about the routes which I noticed later, which goes like
ActiveAdmin: ActiveAdmin::DatabaseHitDuringLoad: Your file, app/admin/account_tags.rb (line 4),
caused a database error while Active Admin was loading. This is most common
when your database is missing or doesn't have the latest migrations applied.
To prevent this error, move the code to a place where it will only be run
when a page is rendered. One solution can be, to wrap the query in a Proc.
Original error message: PG::UndefinedTable: ERROR: relation "account_tags" does not exist
Solution
I ran rake db:migrate and restarted the server, the problem was gone.