Created an entry in rails console, but app has no idea it exists - ruby-on-rails

I entered
SiteData.create(site_name: "My Site", url: "http://mysite.com")
in the console, SiteData being one of my models. Now I can write SiteData.find(1) and it will echo back the entry. Great!
I'm using the db table to store all the info about my site, such as the name, the url, the Facebook page, the Google Plus pages, etc. SO I need to access it on every page. Okay, I'll use before_filter in the application controller to make this work, right?
So I went into my app, and in the Application controller, I wrote
before_filter :add_site_data
def add_site_data
#site_data = SiteData.find(1)
end
And I get an error: "Couldn't find SiteData with id=1"
What now????
This might not be the best way to do this. I am brand new to rails. But I'm totally stuck and have no idea what's going on or why here. I installed Postgres locally today and set up the test and dev dbs, but it seems to be working fine since I can still create/read/update/destroy entries from the console.
Please help! I'm going nuts here. I am using Rails 4.0.

Resetting the server fixed it.
If you know you're making entries in your database that aren't reflected when you run your app, reset the server.

Related

Ruby on Rails link generated with link_to helper no longer works in Chrome

Chrome has been making a lot of changes recently, and one of them has broken a code statement I use to retrieve a document stored in a database, related to a parent record. The action to upload the file and create the attachment relationship is working, so my users can still add documents. They can no longer download and view stored document attachments. The code is using the link_to helper method, and appears to be building the link correctly, verified by the fact that it still works using Edge, so my users have an ugly workaround, but I need to understand what is happening. I have confirmed that it is indeed Chrome that is the problem, because at first I couldn't recreate the defect in development (until I updated my Chrome browser to current version.) Now I can recreate the defect in my development environment.
When the link in my form is clicked, Chrome displays an error screen with this text:
This page isn't working
(*localhost*) sent an invalid response
net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
If I extract the link using developer tools and try and execute it in an empty browser window, I get the same error.
The link is constructed like this:
(*name of the file attachment*)
Before you ask, yes, I have confirmed there are no commas or quotes in my file names! lol
I am hoping someone somewhere can point me to a solution, hopefully simple, maybe obvious, that I can use to get my web form to play nicely with Chrome again - application code change, web server configuration (I am running on RHEL7 Apache in production and Puma in development, my database is Oracle, and I am building with Ruby 2.3.6 and Rails 5.1.5, along with many many gems).
I hope I have covered all the relevant points. Thank you for taking the time to read this post!
Issue has been resolved by upgrading gem attach to version >= 1.0.5. Many thanks to the gem author for excellent responsiveness.

Rails form doesn't show up on heroku

I have a Rails app on Heroku with a couple of forms on it. They show up fine locally, but on heroku, my form doesn't show up at all. I know my database is being accessed, because I have a greeting message with a user's name at the top of the page that's displayed fine.
Has anyone run into this issue and had any luck solving it?
Try to run your app locally on production environment and check is your form show up properly.

Rails App inside a Rails app's sub-folder

I have a rails app, but a client wants to have another rails app be hosted in a ssub-folder of the first rails app.
I can't find any help on how to do this or if it's possible, because if I go to:
http://example.com/second_app, the first app will try and route it despite another app being situated in the second_app folder.
I hope this makes sense, and someone will be able to help.
Sorry, two Rails apps with one inside the other is not possible.
If all you want is a special page for the client, you need a view, controller, and route:
$ rails g controller Pages second_page
And then change your route (config/routes.rb) from get 'pages/second_page’ to get '/second_page’.
After starting up your rails s, you can then go to localhost:3000/second_page and see your page.
If I’m completely misunderstanding what you’re trying to do, please describe your situation a bit more and I’d be happy to help.

Heroku app url made out of random words

I'm new to rails and heroku, and this may very well seem like a daft question, if so I appologise, but would appreciate someone at least telling me so.
I've followed the heroku "getting started" guide, and managed to deploy a copy of the rails default project. But the url preovided by heroku was http://radiant-ice-84.heroku.com, my question is this:
Does heroku assign a randomly generated url, or have I done something wrong because I don't recognise radiant-ice-84?
Before you closing this question, I would like to say that you in fact could specify the first when you create the app (no need to change again in the setting page) by using:
heroku create your-app-name
If you don't specify a name, Heroku generates one for you. You can change it in your app settings (as you noticed), although a lot of people just buy a domain name and map it to the Heroku-generated name.

Troubleshooting: Rails can't save to database in production?

I could use a little help trouble shooting this problem.
When using the app to create a new record nothing is being saved to the database.
There are no visible errors presented.
Dropping to the command line, and using the console with the same production environment, I can create a new object and save it (I have to bypass validations). If I look in mysql database I can see the record that I created from the console.
App works fine locally.
Any thoughts on what might be the problem?
Rails 2.0.2
Sounds like a validation error.
In your controller, try using save! (with the bang) to see if will throw a meaningful error.
I am not sure what code you have in the controller, but this might help show the problem
if my_object.save
log.debug 'object saved correctly'
else
log.debug my_object.errors.full_messages
end
Good luck, if this doesn't help. Try posting the relevant controller and model code.
Have you double checked that the request (with params, etc) works correctly in development?
If not, perhaps looking at the production log file will tell you where the request was routed (e.g. which controller and action, and with which parameters).

Resources