Continuing with my Rails Library Management App, I learnt about scaffolds and thought that it would give me ample framework to re-work upon. The thing is, that although scaffolds are being generated and everything, they aren't working properly. Rather, they aren't working at all.
When I access to http://localhost/[controller-name], It shoots up a webpage that says Listing [controller-name] all fine. But when i click on new button or navigate to http://localhost/[controller-name]/new, the server crashes without an error.
P.S.
While trying things, I noticed that although,
$ rails generate scaffold person name:string identity:integer DOB:date
works just fine,
$ rails generate scaffold student name:string id_number:integer class:integer section:string issued:date returned:date fine:integer reissued:date
doesn't?
P.P.S.
The real problem is, accessing the action "student#new" does not only NOT work, but also crashes my server (yeah no exiting WEBrick). All I can provide are the messages that appear at the end:
Started GET "/assets/students.css?body=1" for 127.0.0.1 at 2015-08-05 12:20:19 +0530
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2015-08-05 12:20:19 +0530
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2015-08-05 12:20:19 +0530
Started GET "/students/new" for 127.0.0.1 at 2015-08-05 12:20:21 +0530
Processing by StudentsController#new as HTML
class is a keyword in Ruby, so using that as a column name isn't a great idea. On this line:
$ rails generate scaffold student name:string id_number:integer class:integer section:string issued:date returned:date fine:integer reissued:date
change class:integer to kind:integer and it should work.
Related
Started GET "/node_modules/src/formSubmitDispatcher.ts" for ::1 at
2022-10-09 18:10:14 -0500 18:10:14 web.1 | 18:10:14 web.1 |
ActionController::RoutingError (No route matches [GET]
"/node_modules/src/formSubmitDispatcher.ts")
This is the error I see in the rails server. I do not see any error on the actual webpage an everything keeps working expect for the new feature I'm adding. It's a slideover form for adding comments to a blog using MRUJS/Cable Car. I have found the formSubmitDispatcher.ts file in the directory tree, but is located at /node_modules/mrujs/src/formSubmitDispatcher.ts. For some reason the path is wrong. Is there a way to fix this? This is not code that I wrote myself. It was generated as part of installing MRUJS. I'm happy to provide any relevant information, but as of right now I have no idea what that might be.
* Listening on tcp://0.0.0.0:3000
Started GET "postinstall/" for 127.0.0.1 at 2013-10-27 07:26:15 +0000
ActiveRecord::SchemaMigration Load (1.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
This is basically it, all my buttons linked to helpers like:
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
Only all the links are like this:
http://localhost:3000/postinstall/users/sign_in
I've been through my log and at one point requests just start being effectively poisoned by this "postinstall" business.
I've grepped for 'postinstall' because surely this word can't be coming from nowhere. I decided to sleep on it because I thought it must be a stupid mistake, but now I need help and unlike 99.9% of my previous questions - it doesn't seem this one has been answered whatsoever.
Searching for even the query "postinstall" on Google yields terrible results.
I THINK my problem lies in a path helper, everywhere the 'postinstall' is getting prepended to requests/urls - the path is referred to like so:
Test
<%= link_to "Sign In", new_user_session_path, :class => "btn btn-success" %>
Where the first link would work route OK, but then the buttons to Submit the login form are trying the POST to /postinstall/users/sign_in etc... The second button would be a link to /postinstall/users etc.
I have absolutely no idea how this started, I've been over my git log and even going back 3 or 4 days (this issue started last night) the error still persists.
Is it seemingly specific to my Mac too, deployed to a dev site (Ubuntu) with no issues. I have restarted my mac etc. Any help is very obviously appreciated...
I had the same problem.
I'm using puma as webserver, and puma uses a ENV called 'SCRIPT_NAME' which was setted with 'postinstall' value after i installed a software, doing puma inject 'postinstall' on url.
if you still having this issue, unset SCRIPT_NAME var from your ENV, using the command on shell unset SCRIPT_NAME.
If you are using TotalTerminal, the recent update leaves the SCRIPT_NAME environment variable set after the update. Rebooting the computer solves the issue.
I started a new topic on Binary Age's support site to try to get this fixed: http://discuss.binaryage.com/t/totalterminal-update-overrides-script-name-breaks-webservers/897
I have two rails applications (both now on Rails 3.1.1), and they work nicely. However, I have a dependence between the two. Application A uses data of application B by linking to it. These links are created automatically, but they have to be computed by doing a lookup to the data of application B. I'm working on Windows 7 with Ruby 1.9.2 and Thin as web server, and this will not be changed :-(
I have tried the following:
Use just a RESTful resource, so defined a controller, called its action (get_xml_obj with some params in it), read the needed values from the XML. Worked, but needs around 0.5s to 1s per call.
Replaced it by ActiveResource#find which worked as well, but with the same performance as the solution before.
I have installed nginx and configured it so, that the connection are keepalive, so that the connection handling should be much faster. But noticed no difference at all when calling B from A.
When I compare the time spent, these are typical examples (here with 4 references in one web page):
Application A:
Started GET "/tasks/search_task/1803" for 127.0.0.1 at 2011-11-02 14:11:04 +0100
Processing by TasksController#search_task as HTML
Parameters: {"id"=>"1803"}
Rendered tasks/_tooltip.html.haml (4529.5ms)
Completed 200 OK in 4532ms (Views: 4527.5ms | ActiveRecord: 2.0ms)
cache: [GET /tasks/search_task/1865] miss
Application B:
cache: [GET /service/get_xml_obj?key=notice&value=rails] miss
Started GET "/service/get_xml_obj?key=notice&value=rails" for 127.0.0.1 at 2011-
11-02 14:11:05 +0100
Processing by ServiceController#get_xml_obj as */*
Parameters: {"key"=>"notice", "value"=>"rails"}
Completed 200 OK in 6ms (Views: 3.0ms | ActiveRecord: 1.0ms)
and 3 other calls with a similar length (< 10ms).
So is there something I can do to tune the retrieval (without accessing the database directly)? Do you know of any good documentation how to measure and tune the web server and middleware? These are only personal applications, so there is no way of deploying them on a decent server. I use a cache for the retrieved information, so it gets better over time, but 1 second is too much to wait for. And there may be more than 1 or 2 links in a page I want to render.
Ok, I finally gave up and implemented the following:
Added file b.rb to my models directory in application A.
Included there all raw models, where the base models (used sti) are defined like that:
class Notice < ActiveRecord::Base
self.establish_connection(
:adapter => "sqlite3",
:database => "../b/db/dev.db"
)
end
...
I am now able to ask: Notice.where(:key => 'rails') which results in a real Rails model object.
The whole thing was implemented in around 20 minutes, and now there is no difference in including no link from application A to B to include 5 links.
At some point in time, I would like to know what is the slow part in using RESTful resources here ...
I'm using Rails 2.3.8 with Ruby 1.8.7 (both installed via CPanel) and gem 1.3.7 and I'm using MongoDB.
Well, I get the following error when I'm trying to create an user (class User):
Processing UsersController#create (for 127.0.0.1 at 2010-11-13 16:09:55) [POST]
Parameters: {"commit"=>"Create", authenticity_token"=>"3AdGHqazhzJUddjLDIKSNzcGTR8KN1Hh7PL+9+vrJ74=", "user"=> "name"=>"jqa"}}
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)
Rendering /home/jqa/public_html/web/public/422.html (422 Unprocessable Entity)
Any Help? Thanks in advance
Are you using rails form helper to generate the registration form? I guess not and thats why you are getting this error. I suggest you to use form_for or form_tag method for the form.
You are getting this because rails generate an authenticity token along with the generated form which gets posted back on form submit as a hidden field. With this rails can assume that it is an authentic request from the same app.
If you have generated the form with hand crafter html, this hidden field wont be there in the form and that why rails is cribbing about it!
there is a scaffold created Story... and in the create action, there is
#story = Story.new(params[:story])
i was curious as to what is in params... so i want to dump out params... but there is no view associated with the create action... is there a way to dump out its content? is there a way to dump out the POST variables in of my code too? (to see what's going on in the lower level)
The easiest thing to do is just dump params out to the log:
Rails.logger.info("PARAMS: #{params.inspect}")
If you're in development mode, just look in your development.log and that line will be there.
The params scope is a combination of URL/FORM (GET/POST) fields, and it will be printed out in the log as part of the normal output processing, so you might not need your own dumping of it - any development or production log contains the params dump at the top of the log line, e.g.
Processing Clients::ClientsController#show (for x.x.x. at 2009-05-24 00:34:26) [GET]
Parameters: {"id"=>"303", "user_id"=>"2"}
Now I know Rails more, you can also simply use a
p params
in your code and look at the console's output (the log shown on the console)
If you're on a Mac, Spike is a great little app the analyses log files and will let you inspect params for requests, amongst other things.
Using Fiddler on Windows, it is shown
the HTTP line #1 is:
POST /stories HTTP/1.1
this is the POST content:
authenticity_token=62iw%2BrsxlCFsbnxsS7FXKRn6CcvJfjottrsBPlM5lZo%3D&story%5Bname%5D=Google+Main+Site&story%5Blink%5D=www.google.com&commit=Create
listed in a table:
authenticity_token 62iw+rsxlCFsbnxsS7FXKRn6CcvJfjottrsBPlM5lZo=
story[name] Google Main Site
story[link] www.google.com
commit Create
and the server log is:
Parameters: {"commit"=>"Create", "story"=>{"name"=>"Google Main Site", "link"=>"www.google.com"}, "authenticity_token"=>"62iw+rsxlCFsbnxsS7FXKRn6CcvJfjottrsBPlM5lZo="}
You don't need to anything except look in your logs (they live in /log). Unless you're fiddling with something, the logging of parameters is turned on by default in all logs.
Processing PostsController#create (for 127.0.0.1 at 2009-05-24 13:03:24) [POST]
Parameters: {"commit"=>"Create", "authenticity_token"=>"2G6BKOs8xNAaXiToVf4r1ko8QZzP9QAomi2PHVQC5Oc=", "story"=>{"something"=>"asdfafd"}}
Parameters lists all parameters, and the hash following "story" is the equivalent of params[:story] (everything comes to the server as strings, and Rails turns it into a HashWithIndifferentAccess so that you can access it with a symbol).
If you're on a *NIX system (including OS X) open a new terminal window/tab and type the following command:
tail -f log/development.log
You'll get a constant stream of requests coming in -- including params -- and the resulting DB actions. Invaluable for development/debugging, IMO.