I've been following rails casts #221, i author using find_by_somefield! with "!". What does that mean in context of ActiveRecord find condition?
It raise an ActiveRecord::RecordNotFound error.
reference: rails guide
see the below link. You will get the answer.
http://rorguide.blogspot.in/2011/06/active-record-finder-methods-dynamic.html
Related
I have a column named _SOMETHING as part of an object created with rails g scaffold, say: rails g scaffold Person _SOMETHING:string
In the create method, when doing #person.save, an error pops up saying that it doesn't find method something(no underscore and lowercases).
Why is it looking for a method with that name?
I patched it by creating
def something
true
end
in my Person model. I am sure that's not the correct way to solve this.
Using Ruby 2.2.2, Rails 4.2.1
Thanks in advance
Turns out the model had a validation where I misspelled the column name, failing each time. Changed the name to _SOMETHING and it worked.
Thank you all for your attention to this silly issue
I just switched rails console to use pry.
I'm also using ruby 2.1.2p95, rails 4.1.5, neo4j (3.0.0.alpha.11), neo4j-community (2.1.3), neo4j-core (3.0.0.alpha.19)
While executing the command show-models it failed, returning the following error:
[3] pry(main)> show-models
ArgumentError: wrong number of arguments (1 for 2..3)
from /home/pdipietro/.rvm/gems/ruby-2.1.2/bundler/gems/neo4j-2e41203410cc/lib/neo4j/active_node/has_n.rb:79:in `has_one'
has anyone an idea on how to circunvent it?
Thank you
Paolo
Look in your models, one of them has a bad has_one call. Every has_one requires at minimum two parameters: a direction and an association name. That indicates you have one that's probably using the old syntax, just doing has_one :association. See documentation at https://github.com/neo4jrb/neo4j/wiki/Neo4j-v3-Declared-Relationships.
EDIT: Unfortunately, I just tested and it doesn't look like show-models doesn't recognize these models. You can add an issue at https://github.com/neo4jrb/neo4j and we can work on adding support. The error you're reporting still has nothing to do with pry, though.
Also, 3.0.0.alpha.11 is quite old at this point, the gem has been released and is now up to 3.0.1. You should really update.
I have been working on implementing the Ancestry gem in my rails app, I have almost got it working the way I want it to.
I am having problems with the following line of code from the Ancestry README docs.
TreeNode.find_by_name('Crunchy').subtree.arrange
The code that I am using in my app is as follows:
Message.find_by_name('FedEx').#messages.arrange
With this, I am getting an error message:
syntax error, unexpected tIVAR
...find_by_name('FedEx').#messages.arrange );#output_buffer.saf...
...
Can anyone tell me what I am doing wrong, or explain to me what TreeNode and subtree should be replaced with?
I belive what you want is: Message.find_by_name('FedEx').subtree.arrange.
Message class should implement ancestry via has_ancestry according to the README.
It's happening on teh lp.save line. Which is weird, because I have the same code else where (slightly different though) for re-sorting the link_pages.
the menu bars and link pages are a has and belongs to many relationship
this is in the menu_bar/destroy method
#menu_bar.link_pages.each do |lp|
lp.sequence = LinkPage::NOT_USED
lp.save
end
also, rails 2.3.8
If you loaded link_pages via an ARel :join query, you can probably get rid of the error by changing :join to :include.
A similar question with a more detailed answer was answered here.
You can also use :readonly => false in your find options.
Look at https://stackoverflow.com/a/960903/327786
It works if you use rails 2.3.15 at least.
I tried doing this when in rails console:
puts about_home_index_path
It gave me an erorr, why is that? should it work?
It was answered here: Rails: how do you access RESTful helpers?
You should use:
puts app.about_home_index_path