I need helping getting Autocomplete working on my Solr Search bar.
Am, using this https://github.com/xponrails/sunspot_autocomplete
Followed the steps & it doesn't work.
I get stuck at my search bar -how do I add it to it, while keeping the params[:search]
Someone else had the same problem, but deleted their code that got it working.
*Does it have to do purely with jquery-ui autocomplete?
Or was there something with having to install the plugin a certain way -I'm not sure if I installed it correctly.
Thank You =)
Please find the steps for auto complete. I am going to give an example for auto complete with items.
Step 1: Create a auto complete text field like <%= text_field_with_auto_complete 'item', 'name' %>
step 2: Then call a method named auto_complete_for_item_name.
setp 3: Inside that method get all the rows from the table and keep it in a variable called #items.
step 4: Then call a new method with this #items variable. Like render :inline => "<%= auto_complete_result #items, 'name','med_item'%>"
step 5: In that method put like this content_tag("ul", items.uniq.join)
It will list all the items based on the entered key.
Please correct me if i was wrong..
Thanks & Regards,
Viji Kumar.M
i just tried it for my project and it worked fine with this steps
all necessary sunspot gems were included and installed (https://github.com/sunspot/sunspot/blob/master/README.md)
autocomplete gem was installed, of course, too (i used little different git path gem 'sunspot_autocomplete', ">= 0.0.3", :git => 'git://github.com/xponrails/sunspot_autocomplete.git' than proposed in manual)
app was restarted after gems added
sunspot generated solr schema.xml was modified (all necessary nodes were added inside blocks
<schema name="sunspot" version="1.0">
<types> *here* </types>
</fields> *and here* <fields>
</schema>)
solr was restarted after schema.xml modified
checked if it started fine with correct! xml (what i mean pointed here)
necessary rows in searchable do; ...; end block for the model were included (it has to be text field and autocompelte field with unique name addressed to text field with :using=>:[text field name] syntax)
model was reindexed after searchable block changes
necessary javascript libraries were included into application.js (i had to copy all js files from gem to app asset folder)
basic styles were included into application.css (same situation as with js files)
assets need to be precompiled (if you try to get it to work in your production environment)
correct autocomplete_text_field was added to view (i had to .html_safe it because it was rendered as raw text)
app was restarted again
and it worked!
but i guess in one or more of this steps you missed something
if the all question is how to add the search field to template - you just need to add this row
<%= autocomplete_text_field("uniq", "field", "http://localhost:8982/solr/", "uniq_field") %> - assuming you have indexed autocomplete :uniq_field, :using => :field and pointed it to the live version of solr (http://localhost:8982/solr/)
if you share with me some code i can point you to something you missed
cheers!
Related
I have some problem/issues with active admin on rails, specifically unpermitted params error:
existing active admin parameter
here is the existing active admin parameter
model associated with the main model im working with
As per active admin documentation I should be doin right, as the other attributes for dispatch_information model is being accepted by rails and I was able to read and write with out any issues. Just with this recently added attribute "custom_attorney". Associations already set. and with out declaring an attr_accessor on model file it says this error
No method error
as it seems it cannot read or detect the column that I added for dispatch_information model, while in my console its already there.
When I add it with attr_accessor "while it should not, just to proceed on the form page" then I fill in the attributes need, im getting weird stuff in my console
Console view
as you can see it seems it being added inside efile_order hash instead of dispatch_information_attribute hash, and at the bottom part of the image you can see it says unpermitted parameters, even I added it inside the correct attribute block, we can also notice that the other attributes pf dispatch_information works really fine, just this recently added custom_attorney attribute. I already did everything like migration and other stuff.
Form Input
here is my form where we can see that input is on the same block where dispatch_defendant and dispatch_plaintiff is included and those two attribute works fine as well.
I really dont know what I missed here. TIA
The problem is that custom_attorney should be nested under dispatch_information_attributes you have it in the wrong place so it's unpermitted.
The correct way to do that is to add a block for those attributes and nest them.
- f.simple_fields_for :dispatch_information do |d|
- d.input :custom_attorney, :input_html => { id: 'new-attorney' }
It may be a good idea to provide an object for dispatch_information if you care for existing data. Assuming your ivar is named #e_filling_order then you should have the following.
- f.simple_fields_for :dispatch_information, #e_filling_order.dispatch_information || #e_filling_order.build_dispatch_information do |d|
OK, so originally I followed this guide to create a fulltext index, and then I imported all my data onto my Neo4j server. The indexes work great, and now I'm trying to use Sinatra/Ruby to interact with my Neo4j graph.
I'm using the Neo4j ruby gem, and I've created a model (movie.rb) of Movies with a fulltext index on the title as per this wiki entry:
class Movie
include Neo4j::NodeMixin
property :id
property :movieID
property :name, :index => :fulltext
property :year
property :imdB
property :rtRating
property :poster
end
However, I am getting this error: NameError: uninitialized constant Neo4j::NodeMixin. The Neo4j Ruby wiki entry states that:
The neo4j-wrapper is included in the neo4j gem The neo4j-wrapper gem defines these mixins: Neo4j::NodeMixin
So it should be included in my project...
I have no idea how to continue... someone please help me search with my fulltext index?
I think we've already helped you with this separately, but for anybody running across this question:
For various reasons, the Neo4j.rb project doesn't have good support for the legacy indexes. That wiki page is out of date (I just updated it to say so). The searchkick gem is recommended for fulltext search functionality with Neo4j.rb.
Also note that there is a direct integration of elasticsearch with Neo4j:
https://github.com/neo4j-contrib/neo4j-elasticsearch
Here's a video tutorial:
https://www.youtube.com/watch?v=SJLSFsXgOvA
For that, though, I believe you would need to make your own HTTP requests to Neo4j to get the results from the plugin. The upside is that not all of your changes need to go through your Ruby app (like would be the case with searchkick)
I need to be able to share local data (in a yaml file) from templates with a layout. I want to be able to load relevant YAML data in the template then have that data be accessible from the layout (and associated partials). Is this possible?
I found this blog post which seems to indicate that this is possible through some shennaigans but I can't get it to work and this seems hacky. Is there a built in way to pass data between templates and layouts? And if not, can the hack in this blog post be made to work?
Update: now featuring code!
Here is code from the blog post linked above. I tried it exactly as show, and played with it a little, but no dice.
# in your layout file (inside layout/ folder):
<% myvar = yield_content :myvar %>
<% myvar = eval(myvar.to_str) %>
# in your template file (e.g., mypage.html.erb):
<% content_for :myvar, data.somefile %>
# this examples assumes there's a somefile.yml in your data/ folder:
name: hello world
tag: the quick brown jumps over the lazy dog
The above code returned no implicit conversion of nil into String which sounds like the YAML file either didn't load or was't passed to the layout (since it's loaded in the template.) I confirmed it was loading in the template so maybe it wasn't being passed to the template for some reason? (Aside: as a new programmer I've been taught eval is the devil's work and to "never use it" so this solution seems sketchy to me.)
On my own I tried to do something like the below, and if the YAML is loaded into the template like so:
data = YAML.load_file('some/file/data.yml')
it works fine within the template but the layout throws undefined local variable errors.
The same, but reverse, is true if you load the YAML into the layout, it won't be accessible in the template. Additionally, I don't want the data loaded in the layout because it will be different depending on the template it's coming from.
Ideally I would just pass the loaded YAML data from the template to the layout, but I think I could also achieve my ultimate goal if the layout new for which blog (it's a multi blog site) it was being called on. However after talking with some people on the Middleman team that route does not appear to be an option.
It turns out all you have to do to pass data from a template to a layout is declare an instance variable. So for YAML data like I was doing:
# In your template
<% #my_var = YAML.load_file("path/to/data.yml") %>
# In your layout
<p>My_var contains: <%= #my_var %></p>
I don't know if this is obvious if you're familiar with the tool chain underneath middleman, or if it's in the documentation somewhere and I just couldn't find it, but that's all there is to it.
Thanks so much to #dddd1919 for dropping this knowledge bomb.
I have an ElasticSearch server running that indexes and searched documents using the excellent Tire gem. Everything works great, except I'm not sure how to go about manually removing documents from the search index.
I have poured over the RDoc and searched for hours, but this is the only hint at a solution I can find https://github.com/karmi/tire/issues/309. Is there an easier way other than building a custom wrapper around curl and making the request manually?
Another hitch is that I use a soft-delete gem called ActsAsParanoid, so the Tire::Model::Callbacks won't remove the object on soft-delete.
Any ideas?
In case you only have the ID (e.g. 12345):
User.tire.index.remove 'user', '12345'
Or more generally:
klass.tire.index.remove klass.document_type, record_id
(which I think is equivalent to what remove #user will do behind the scenes)
reference
Turns out you can just manually remove the soft-deleted Object from the index like so:
#user = User.find(id) #or whatever your indexed object is
User.tire.index.remove #user #this will remove them from the index
Thats it!
I am trying to setup the Twitter gem, and I feel like I'm almost there... kind of.
Right now I was trying to follow this link:
http://www.phyowaiwin.com/how-to-download-and-display-twitter-feeds-for-new-year-resolution-using-ruby-on-rails
It is a bit old though, and I guess its instructions are a bit out of date. I have created a twitter model, twitter db migration and a twitter controller(not sure it's needed though), and if i open rails console, and I type:
Twitter.user_timeline("whatever").first.text
It just works. I just can't seem to be able to see it in my view. can you point me in the right direction?
Thanks a lot!
Alex
In your controller that corresponds with your view, you need to assign your results to a variable inside the appropriate functionlike so:
def controller_function
#twitter_data = Twitter.user_timeline("whatever").first.text
end
Then, in your corresponding view you can use the variable
<%= #twitter_data ... %>
Check out http://guides.rubyonrails.org/layouts_and_rendering.html for more guidance on controllers and views