I'm getting the following error
i created a new scaffold bid with few fields
when i tried to access localhost:3000/bids/new
i get following error
ActiveRecord::DangerousAttributeError in BidsController#new
save is defined by ActiveRecord
in server side i see this result:
Started GET "/bids/new" for 127.0.0.1 at 2013-09-07 12:52:43 +0530
Processing by BidsController#new as HTML
Refinery::Role Load (0.4ms) SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."title" = 'Refinery' LIMIT 1
Refinery::User Load (0.3ms) SELECT "refinery_users".* FROM "refinery_users" INNER JOIN "refinery_roles_users" ON "refinery_users"."id" = "refinery_roles_users"."user_id" WHERE "refinery_roles_users"."role_id" = 1
Completed 500 Internal Server Error in 779ms
ActiveRecord::DangerousAttributeError (save is defined by ActiveRecord):
app/controllers/bids_controller.rb:27:in `new'
app/controllers/bids_controller.rb:27:in `new'
what am i missing or is refinerycms mounted at / is overriding functions?
please help me
It Seems, you have defined some reserved ActiveRecord's attributes, If you did so, than you either have to change those or try something else. Just add a gem in your gemfile and the gem will take care of name collisions automatically.
gem 'safe_attributes'
hope it will help. Thanks.
I have solved my problem,
The problem is not with refinery cms
i created a field with name save:boolean
i changed it to save_x:boolean and now it works fine
Related
A colleague added a new record for the class "Production" via our rails admin interface, which is the parent class via STI of the subclass "CoProduction".
The type attribute was by mistake filled out via the rails_admin with a value that is not the specified subclass "CoProduction", but with a wrong one. As a result I cannot delete nor update the record from rails console in our AWS environment (and the rails admin interface has crashed and is not starting over again either).
[1] pry(main)> Production.last
Production Load (1.0ms) SELECT "productions".* FROM "productions" ORDER BY "productions"."id" DESC LIMIT $1 [["LIMIT", 1]]
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism
failed to locate the subclass: 'opera buffa'. This error is raised
because the column 'type' is reserved for storing the class in case of
inheritance. Please rename this column if you didn't intend it to be
used for storing the inheritance class or overwrite
Production.inheritance_column to use another column for that
information.
EDIT
I could solve the issue meanwhile, by connecting via PGADMIN to the db instance,retrieving the culprit record and modify it. Unfortunately this error was not to be solved in an ActiveRecord environment
It seems that the record was somehow added by skipping the default validation defined for STI. You can follow the same way to recover the record and set its proper type by using:
ActiveRecord::Relation#update_all, which neither instantiates the involved models nor triggers Active Record callbacks/validations.
In rails console, find all occurrences of wrong types (e.g. opera buffa) in Production model and update it to type CoProduction:
Production.where(type: 'opera buffa').update_all(type: 'CoProduction')
Production model should work as usual after this point.
I could solve the issue meanwhile, by connecting via PGADMIN to the db instance,retrieving the culprit record and modify it. Unfortunately this error was not to be solved in an ActiveRecord environment
I am developing a website for a journal in Rails and on one of my pages has a list of every single issue that has been published in descending order. I also have a select box for users to filter the issues by year as they don't have names but hopefully, it will help them to find what they are looking for more quickly if the article within an issue isn't uploaded to the site separately.
In order to create the options for the filter box, I made the following function to return a list of all the unique years for the issues (an Issue has a date field that is the publish date of the issue, in case old issues that precede the website need to be uploaded).
Issue.select("date").order('date desc').map{ |i| i.date.year }.uniq
This function works excellently on my own machine but when I deploy it on Heroku (a free account), it gives the following error message when I check the logs.
2017-08-15T15:19:42.521061+00:00 app[web.1]: Started GET "/issues" for 83.136.45.169 at 2017-08-15 15:19:42 +0000
2017-08-15T15:19:42.522804+00:00 app[web.1]: Processing by IssuesController#index as HTML
2017-08-15T15:19:42.524822+00:00 app[web.1]: Issue Load (0.9ms) SELECT "issues"."date" FROM "issues" ORDER BY date desc
2017-08-15T15:19:42.525378+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.9ms)
2017-08-15T15:19:42.525925+00:00 app[web.1]:
2017-08-15T15:19:42.525926+00:00 app[web.1]: NoMethodError (undefined method `year' for nil:NilClass):
2017-08-15T15:19:42.525927+00:00 app[web.1]: app/controllers/issues_controller.rb:12:in `block in index'
2017-08-15T15:19:42.525927+00:00 app[web.1]: app/controllers/issues_controller.rb:12:in `index'
I have made no changes to the database since my last push. I'm not sure how to further debug this situation.
The error is not caused by heroku, but by the data you have in the database on heroku. You seem to have records in the Issue table that were created without a date.
To avoid this, use this query:
Issue.where.not(date: nil).select("date").order('date desc').map{ |i| i.date.year }.uniq
I think the query above works only with Rails 5.
If you use a previous version, you can do this:
Issue.select("date").order('date desc').map{ |i| i.date&.year }.uniq.compact
Notice the i.date&.year and the compact. The & will not execute the following method if date is nil.
However, it will probably add nil objects to your array, resulting in something like this:
[year1, year2, nil, year3]
compact will remove nil objects, to obtain this:
[year1, year2, year3]
More information:
http://mitrev.net/ruby/2015/11/13/the-operator-in-ruby/
I have a working rails app on my local machine. I updated my Heroku and started to test it. One of my views requires the controller to add elements to an array using unshift.
When I go to this view on the web, I get an error We're sorry, but something went wrong.
I went into $heroku logs and the most recent errors are:
2014-02-28T02:08:26.650021+00:00 app[web.1]: NoMethodError (undefined method `unshift' for #<ActiveRecord::AttributeMethods::Serialization::Attribute:0x007fe57862f588>):
2014-02-28T02:08:26.650021+00:00 app[web.1]: app/controllers/users_controller.rb:32:in `show'
Any ideas how to fix this?
my controller function looks like this:
#user.daily = #user.daily.unshift(day)
#user.daily is a serialized array
#Mhsmith21, if day is an object and if you are rails 4+ then my suggestion is to use build instead of unshift.
If you are using unshift to add the object on first position then use build and reverse the array.
As unshift does not work for ActiveRecord::Associations::CollectionProxy.
I'm running a Rails app (v 3.1.10) on a Heroku Cedar stack with Papertrail add-on going crazy because of the size of the logs.
My app is really verbose and the logs are getting huge (really huge):
Sometimes because I serialize a lots of data in one field and that makes a huge SQL request. In my model I have many:
serialize :a_game_data, Hash
serialize :another_game_data, Hash
serialize :a_big_set_of_game_data, Hash
[...]
Thanks to my AS3 Flash app working with bigs sets of json...
Sometimes because there's a lots of partials to render:
Rendered shared/_flash_message.html.erb (0.1ms)
Rendered shared/_header_cart_info.html.erb (2.7ms)
Rendered layouts/_header.html.erb (19.4ms)
[...]
It's not the big issue here, but I've added this case too because Jamiew handle it, see below...
Sometimes because there's lots of sql queries on the same page:
User Load (2.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Course Load (5.3ms) SELECT "courses".* FROM "courses" WHERE (id = '1' OR pass_token = NULL)
Session Load (1.3ms) SELECT "sessions".* FROM "sessions" WHERE "sessions"."id" = 1 LIMIT 1
Training Load (1.3ms) SELECT "trainings".* FROM "trainings" WHERE "trainings"."id" = 1 LIMIT 1
[...]
It's a big (too) complex App we've got here... yeah...
Sometimes because there's a lots of params:
Parameters: {"_myapp_session"=>"BkkiJTBhYWI1MUVlaVdtbE9Eb1Y2I5BjsAVEkiEF9jc3JmX3Rva2VlYVWZyM2I0dEZaR1YwNXFjZhZTQ1uBjsARkkiUkiD3Nlc3Npb25faWQGOgZFRhcmRlbi51c2yN1poVm8vdWo3YTlrdUZzVTA9BjsARkkiH3dAh7CMTQ0Yzc4ZDJmYzg5ZjZjOGQ5NVyLmFkbWluX3VzZXIua2V5BjsAVFsISSIOQWRtaW5Vc2VyBjsARlsGaQZJIiIkMmEkMTAkcmgvQ2Rwc0lrYzFEbGJFRG9jMnZvdQY7AFRJIhl3YXJkZW4udXNlci51c2VyLmtleQY7AFRbCEkiCVVzZXIGOwBGWwZpBkkiIiQyYSQxMCRBUFBST2w0aWYxQmhHUVd0b0V5TjFPBjsAVA==--e4b53a73f6b622cfe7550b2ee12678712e2973c7", "authenticity_token"=>"EeiWmlODoYXUfr3b4tFZGV05qr7ZhVo/uj7a9kuFsU0=", "utf8"=>"✓", "locale"=>"fr", "id"=>"1", "a"=>1, "a"=>1, "a"=>1, "a"=>1, "a"=>1, "a"=>1, [...] Hey! You've reach the end of the line but it's not the end of the parameters...}
The AS3 Flash app send big json data to the controller...
I didn't mention the (in)famous "Assets pipeline logging problem" because now I'm using the quiet_assets gem to handle this:
https://github.com/evrone/quiet_assets
So... what did I try?
1: Dennis Reimann's middleware solution:
http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/
2: Spagalocco's gem (inspired by solution #1):
https://github.com/spagalloco/silencer
3: jamiew's monkeypatches (inspired by solution #1 + a bonus):
https://gist.github.com/1558325
Nothing is really working as expected but it's getting close.
I would rather use a method in my ApplicationController like this:
def custom_logging(opts={}, show_logs=true)
disable_logging unless show_logs
remove_sql_requests_from_logs if opts[:remove_sql_requests]
remove_rendered_from_logs if opts[:remove_rendered]
remove_params_from_logs if opts[:remove_params]
[...]
end
...and call it in any controller method: custom_logging({:remove_sql_requests=>1, :remove_rendered=>1})
You got the idea.
So, is there any good resource online to handle this?
Many thanks for your advices...
I"m the author of the silencer gem mentioned above. Are you looking to filter logging in general or for a particular action? The silencer gem handles the latter problem. While you can certainly use it in different ways, it's mostly intended for particular actions.
It sounds like what you are looking for less verbose logging. I would recommend you take a look at lograge. I use that in production in most of my Rails apps and have found it to be quite useful.
If you need something more specialized, you may want to look at implementing your own LogSubscriber which is essentially the lograge solution.
Set your log level in the Heroku enviroment
View your current log level:
heroku config
You most likely have "Info", which is just a lot of noise
Change it to warn or error
heroku config:add LOG_LEVEL=WARN
Also, when viewing the logs, only specify the "app" server
heroku logs --source app
I personally, append --tail to see the logs live.
heroku logs --source app --tail
I have a threaded Post using Ancestry.
When replying to a Post from another user I get :
on the line :
#post = current_user.posts.new(params[:post])
Started POST "/posts.js" for 127.0.0.1
at Tue Jun 07 13:50:19 +0300 2011
Processing by PostsController#create
as JS Parameters: {"commit"=>"Post",
"post"=>{"body"=>"a",
"parent_id"=>"5",
"discussion_id"=>"1"},
"authenticity_token"=>"RUra0Ndv67cgaGshBS5yCJMq5V6WG6OuZiqDbbWP5cc=",
"utf8"=>"✓"} User Load (0.2ms)
SELECT "users".* FROM "users" WHERE
("users"."id" = 33) LIMIT 1 Post
Load (0.2ms) SELECT "posts".* FROM
"posts" WHERE ("posts".user_id = 33)
AND ("posts"."id" = 5) LIMIT 1
Completed in 238ms
ActiveRecord::RecordNotFound (Couldn't
find Post with ID=5 [WHERE
("posts".user_id = 33)]):
app/controllers/posts_controller.rb:28:in
`create'
How can I debug it ?
My first pass would be to open rails console (at the prompt type 'rails console') and then try the following:
>> x = Post.find(5)
If you find it check the user_id on that record. Does it actually exist? If so, that's good to know.
Next I would take the SQL in your output above and run it manually in whatever db you use. If you're using SQLite3 you can do:
>> sqlite3 db/development.sqlite3
If it exists then it's a fair point to scratch your head. I suspect you will find that it's not there.
Is the link to reply to the post manually created in your view? Are you certain it's being built correctly--the two ids of interest are indeed what you intended them to be?
If it's correctly built then I would simply use the ruby debugger in your controller and begin stepping through code. If you're not familiar with the ruby debugger, you can get the gem as described in your Gemfile and then once it's in your gemset you can add this line of code where you want to breakpoint your code:
require 'ruby-debug'; debugger
Then you're free to explore as necessary.