I have an active record model like this:
#model = ModelClass.find(1)
Then I clone it and make modification:
#clone = #model.clone
Then I change the clone:
#clone.firstname = 'new name'
But then #model.firstname is changed to 'new name' as well. My eyes are almost jump out of my head when I saw this.
Why clone bring such a weird behavior?
Related
I have a code block being auto-formatted as:
.withStuff(ImmutableList.of(Stuff.builder().withName("Animaniacs").build(),
Stuff.builder().withName("Pinky and the Brain").build()))
.build());
That ideally I want idea to auto format as:
.withStuff(ImmutableList.of(
Stuff.builder().withName("Animaniacs").build(),
Stuff.builder().withName("Pinky and the Brain").build()
))
.build());
I doubt I can get exactly what I'm after, it seems idea is failing to honor several settings in the .editorcofig:
ij_java_call_parameters_new_line_after_left_paren = true
ij_java_call_parameters_right_paren_on_new_line = true
ij_java_call_parameters_wrap = split_into_lines
ij_java_keep_line_breaks = true
Can anyone advise how to fix this?
If you put a line-break before ImmutableList.of the default formatting will give you this:
.withStuff(
ImmutableList.of(
Stuff.builder().withName("Animaniacs").build(),
Stuff.builder().withName("Pinky and the Brain").build()
)
).build());
which is not exactly what you wanted but it is much nicer than your first example and it aligns the list items under each other like you wanted.
When a Webhook is triggered, is there a way to get the org_id from which it was fired? (Aside from climbing up the triggered item)
The only solution I found so far is:
PodioItem::get($item_id); to get the space_id
PodioSpace::get($space_id); to get the full
PodioOrganization::get_for_url($attributes = array()); I get the org_id.
See the "Bundling responses using fields parameter" section at the very bottom of https://developers.podio.com/index/api on how you can use the fields query parameter to include more data. There's even an example that goes almost all the way for you (it walks up to the space level, but you can just tack the org onto it):
/item/{item_id}?fields=app.view(full).fields(space.view(full))
For podio-php you can do:
$item = PodioItem::get($item_id, array('fields' => "app.view(full).fields(space.view(full))"));
Use PodioItem::filter instead of PodioItem::get, I'm pretty sure that you'll have the expected results, so try this:
$item = PodioItem::filter($item_id, array('filters' => "app.view(full).fields(space.view(full))"));
Hope it helps!
I've been digging around a little trying to figure out how I should locate the "tweet_id" in my #savedtweets table and then locate that same "tweet_id" in my #newtweets table from a controller, so far I'ved tried something like this;
CONTROLLER
#stweet = Savedtweet.find(params[:id])
#newtweet = Newtweet.where(:tweet_id => #stweet.tweet_id)
#newtweet.status = 'new'
#newtweet.save
Basically I need to change the string "saved" in my Newtweets table to "new" based on the current Savedtweet ID. I just can't figure it out. If I do the following in console;
#stweet = Savedtweet.first
#newtweet = Newtweet.where(:tweet_id => #stweet.tweet_id)
It finds the right one. I've got to be close just not there yet. :)
You could do:
Newtweet.find_by_tweet_id(#stweet.tweet_id).update_attribute(:status, 'new')
The reason your code isn't working is because Newtweet.where() returns an array of objects. It should be Newtweet.where().first, though Newtweet.find_by_tweet_id is the preferred method.
I have a materials model which has a search form. The search action looks a bit like this:
def search
conditions = {}
conditions[:version] = 'master'
conditions[:status] = 'shared'
conditions[:targ_lang] = params[:targ_lang] unless params[:targ_lang].blank?
#results = Material.find(:all, :conditions => conditions)
end
I have added the acts-as-taggable gem and it works fine to save the tags but I'm having trouble adding it to the search form. The documentation states that to find Materials with the tags you can use this code:
Material.tagged_with(["awesome", "cool"], :match_all => true)
But I don't know how to add this condition to the conditions.
Update
#results = Material.where(conditions) && Material.tagged_with(params[:tag_list])
This works provided tags are used but it doesn't work if the tag list is blank so I need a condition as with the other conditions above that the Material.tagged_with ... part is only necessary if the field is not empty.
Update 2 - Bad Solution
This works but it's not very elegant is it?
if params[:tag_list].blank?
#results = Material.where(conditions)
else
#results = Material.tagged_with(params[:tag_list]).where(conditions)
end
This code won't work for you?
Material.where(conditions).tagged_with(['awesome', 'cool'], :match_all => true)
Or the inverse order:
Material.tagged_with(['awesome', 'cool'], :match_all => true).where(conditions)
UPDATE
Reading the docs on the act-as-taggable-one on github, there is a option named :any. Maybe you can try to use it. I don't have a project i could do some testing, but maybe a code like:
Material.tagged_with(['awesome', 'cool', '', nil], :any => true).where(conditions)
Give it a try.
this is my test (with shoulda helpers):
context "searching from header" do
setup do
Factory(:city, :name => 'Testing It')
ThinkingSphinx::Test.index 'city_core', 'city_delta'
ThinkingSphinx::Test.start
get :index,
:query => 'Testing It'
end
should respond_with(:success)
should assign_to(:results)
should "have one city on the result" do
assert_equal( assigns(:results).count, 1 )
assert_kind_of( assigns(:results).first, City )
end
ThinkingSphinx::Test.stop
end
Everything works fine except the test always say the count of the results is 0, not 1.
I have debugged this code and when the request reaches the controller, the Sphinx indexes are completely empty, even with the explicit call of index for it.
Am I doing something wrong here?
Any help appreciated.
I found out the problem... even tho the insertion in the database is right before the ThinkingSphinx.index, with transactional fixtures, after the setup block the records get deleted.
The solution was adding to the test the following line:
self.use_transactional_fixtures = false
Hope this helps anyone with the same problem.