routes lead to blank view, no html - ruby-on-rails

I have a very similar issue to this question: My route returns a blank view (no html when I do view source)
When I access a route, it just shows a blank view with no html when viewing source.
My route returns a blank view (no html when I do view source)
config/routes.rb
SampleApp::Application.routes.draw do
devise_for :users
root to: 'home#index'
end
app/controllers/home_controller.rb
class HomeController < ApplicationController
def index
end
end
app/views/home/index.html.slim (slim is like erb, I tested both out but still no html rendered)
h1 get ready to party!
log/development.log
Started GET "/" for 127.0.0.1 at 2012-12-05 00:36:21 -0500
Processing by HomeController#index as */*
Rendered home/index.html.slim within layouts/application (0.4ms)
Completed 200 OK in 6ms (Views: 5.9ms | ActiveRecord: 0.0ms)
The other question suggested changing ports. I did all the basic stuff like restart server, restart computer, try different ports.

It sounds like your layout could be blank and is not rendering the index view.
The default layout is application.html.erb and should render your views with <%= yield %>.
Also - have you tried restarting your server for kicks? That's the answer to the other SO question you posted so I'm assuming you've tried that...

Related

Newly added Redmine route, view and controller returns 403 error

I'm new to Redmine and Rails, and I have a question I'm stuck with.
I have a timelogger plugin installed from https://github.com/speedy32129/time_logger and it has a redirect option to the IssuesController edit method in Redmine source
https://github.com/speedy32129/time_logger/blob/master/app/controllers/time_loggers_controller.rb#L82
I want to create a custom controller action called edit_realtime, define a route for this and a custom view because I need to do some changes to this view and don't affect the original edit view.
What I've done:
Changed the edit method to edit_realtime in app/controllers/time_loggers_controller.rb:
redirect_to controller: 'issues',
protocol: Setting.protocol,
action: 'edit_realtime',
id: issue_id,
time_entry: { hours: hours }
end
Created a new controller method in app/controllers/issues_controller.rb
def edit_realtime
return unless update_issue_from_params
respond_to do |format|
format.html {}
format.js
end
end
Created a route in routes.rb
post '/issues/new', :to => 'issues#new'
get '/issues/:id/edit_realtime', :to => 'issues#edit_realtime'
Created the needed views in app/views/issue
edit_realtime.html.erb
edit_realtime.js.erb
_edit_realtime.html.erb
The result: 403 error when stopping the time log
View image
full route: http://localhost:81/redmine/issues/1/edit_realtime?time_entry%5Bhours%5D=0.0
and production log
Started GET "/redmine/time_loggers/stop" for 127.0.0.1 at 2021-08-11 16:26:22 +0300
Processing by TimeLoggersController#stop as HTML
Current user: alisa (id=1)
Redirected to http://localhost:81/redmine/issues/1/edit_realtime?time_entry%5Bhours%5D=0.0
Completed 302 Found in 24ms (ActiveRecord: 14.8ms)
Started GET "/redmine/issues/1/edit_realtime?time_entry%5Bhours%5D=0.0" for 127.0.0.1 at 2021-08-11 16:26:22 +0300
Processing by IssuesController#edit_realtime as HTML
Parameters: {"time_entry"=>{"hours"=>"0.0"}, "id"=>"1"}
Current user: alisa (id=1)
Rendering common/error.html.erb within layouts/base
Rendered common/error.html.erb within layouts/base (0.5ms)
Rendered plugins/time_logger/app/views/time_loggers/_embed_menu.html.erb (6.6ms)
Rendered plugins/time_logger/app/views/time_loggers/_update_menu.html.erb (8.5ms) [cache hit]
Filter chain halted as :authorize rendered or redirected
Completed 403 Forbidden in 44ms (Views: 26.3ms | ActiveRecord: 13.1ms)
what did I do wrong?

Rails routes.rb assistance

thanks in advance for your help!!
I have in routes.rb:
get 'api/streets:name' => 'streets#get_by_name', as: "get_by_name"
I have in streets_controller.rb:
ids = params[:name]
I have in Javascript:
const params = encodeURI('name[]=1&name[]=2')
fetch(`/api/streets?${params}`)
When I call the api from the front end, I get the following log message:
Started GET "/api/streets?name%5B%5D=2&name%5B%5D=5" for 127.0.0.1 at 2019-09-06 17:10:59 -0700
Rendering pages/index.html.erb within layouts/application
Processing by PagesController#index as */*
Parameters: {"name"=>["2", "5"], "path"=>"api/streets"}
Rendered pages/index.html.erb within layouts/application (7.1ms)
Rendering pages/index.html.erb within layouts/application
Why is it using the PagesController and not the StreetsController?
In all other cases where I'm getting and posting and putting and deleting on the api, the router knows what controller to use. It's just this one case when I'm using array parameters where it's routing to the wrong controller.
It's probably just something dumb I've done.
Your route expects a path like: /api/streets123 - where params[:name] would be equal to "123" and no, that's not a typo.
You should just use:
get 'api/streets' => 'streets#get_by_name', as: "get_by_name"
If you need to enforce the existence of the :name parameter then you should use the :constraints option.

url parameters are not in params

I want to get information from the TwitchTV OAuth API, and the authorization works well, but I can not get the code that Twitch redirects me to.
For example:
http://localhost/?code=noj4n39487fn29fn23v92hr293hnru23v97hre&scope=
This is how Twitch redirects back to my page. In the log of my rails server it also shows the following:
Started GET "/?code=q5yptiyx3cdaep52b7xyqgt3vjpwhg&scope=" for 371.1721.13.179 at 2015-08-22 17:09:26 +0200
Cannot render console from 315.127.134.179! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by HomeController#index as HTML
Parameters: {"code"=>"q5ypti345ferf2rf2efr2erferfe23ff", "scope"=>""}
News Load (0.6ms) SELECT "news".* FROM "news"
Rendered home/index.html.erb within layouts/home (14.7ms)
Completed 200 OK in 124ms (Views: 120.6ms | ActiveRecord: 1.0ms)
But when I try to get params.inspect in the controller, it shows this:
{"controller"=>"oauth", "action"=>"index"}
my controller looks like this:
class OauthController < ApplicationController
def index
redirect_to 'https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=34n87fn48fn438rzfghb4z8rofg4rg&redirect_uri=http://localhost/'
logger.info params.inspect
end
end
Obviously I changed all the ip's, auth-codes and stuff. My question is, shouldn't params return the parameters since it shows them as parameters (in the first code block) ?
Localhost is local address and 'outworld' API cannot send information back to 'localhost', you have to use http://127.0.0.1 or get a real domain for you development environment.

Rails app redirects root request to /404

I can't figure out why my application isn't working properly.
I've got the following routes.rb:
Rails.application.routes.draw do
root to: 'visitors#index'
# ... other routes
# Default root
get '*path', to: "error#error_404"
end
I enter the http://localhost:3000 in the browser url and get redirected to http://localhost:3000/404. Logs tell me one thing:
Started GET "/404" for 127.0.0.1 at 2015-08-31 14:24:50 +0300
Processing by ErrorController#error_404 as HTML
Parameters: {"path"=>"404"}
Rendered error/error_404.html.slim within layouts/application (0.8ms)
Rendered layouts/_navigation_links.html.slim (2.2ms)
Rendered layouts/_navigation.html.slim (3.2ms)
Rendered layouts/_messages.html.slim (0.1ms)
Rendered layouts/_footer.html.slim (0.1ms)
Completed 200 OK in 876ms (Views: 875.3ms | ActiveRecord: 0.0ms)
Other related files are the following:
visitors_controller.rb
class VisitorsController < ApplicationController
def index
#specializations = Specialization.order(name: :asc)
end
...
views/visitors/index.html.slim
- if #specializations.count == 0
h3.bg-primary.text-center = I18n.t('layout.no_specializations')
- #specializations.each_with_index do |specialization, index|
- if index % 3 == 0
.row
.col-sm-4
= link_to specialization
img src="#{specialization.avatar.url(:thumb)}" /
p.text-center
= specialization.name
- if index % 3 == 2
What can be the issue here?
P.S. When I enter e,g, localhost:3000/specializations/1 the resulting page gets normally loaded.
UPDATE
curl localhost:3000 gets the right HTML, without any redirection.
It turned out to be bad slim code. This line:
img src="#{specialization.avatar.url(:thumb)}" /
should be refactored into
img src=specialization.avatar.url(:thumb) /
Done. works.

No route matches "/index". Simple issue?

New to all coding worlds and new to RoR. I have been doing a tutorial and ran into some issues last night. A friend of mine helped with a few of them. I asked a few here. And yet this one baffles me. I cannot find the issue of it.
The page loads, it shows what needs to be shown. But when I press a link on there it results in this:
Routing Error
No route matches "/index"
So I did rake routes and I got this
Dennis-Buizerts-MacBook-Pro:gpoff dennisbuizert$ rake routes
site_index GET /site/index(.:format) {:controller=>"site", :action=>"index"}
site_about GET /site/about(.:format) {:controller=>"site", :action=>"about"}
site_help GET /site/help(.:format) {:controller=>"site", :action=>"help"}
root /(.:format) {:controller=>"Site", :action=>"index"}
This is in my routes.rb
root :to => "Site#index"
get "site/index"
get "site/about"
get "site/help"
I tried adding map.connects and match but that didn't seem to resolve it.
And my development.log says the follow:
Started GET "/" for 127.0.0.1 at 2011-08-28 10:05:51 +0200
DEPRECATION WARNING: Disabling sessions for a single controller has been deprecated. Sessions are now lazy loaded. So if you don't access them, consider them off. You can still modify the session cookie options with request.session_options. (called from <class:ApplicationController> at /Users/dennisbuizert/Sites/gpoff/app/controllers/application_controller.rb:3)
Processing by SiteController#index as HTML
Rendered site/index.html.erb within layouts/application (1.6ms)
Completed 200 OK in 5ms (Views: 4.3ms | ActiveRecord: 0.0ms)
Started GET "/index" for 127.0.0.1 at 2011-08-28 10:05:52 +0200
ActionController::RoutingError (No route matches "/index"):
Rendered /Users/dennisbuizert/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.8ms)
Try
get 'index' => "site#index"
instead of
get "site/index"

Resources