I'm using the Linkedin gem to pull profile information for RoR 3.
Gem: https://github.com/pengwynn/linkedin
API Doc: https://developer.linkedin.com/documents/profile-fields#positions
Everything works except when I get to a property with a dash in the name.
<%=position.title %> displays correctly but<%= position.start-date %> return a NoMethodError in Users#show - undefined method start.
I've tried different operations like "startDate", "start_date", quotes around "start-date" but none have worked.
Is there a proper way to escape the dash/hyphen in the property name?
The expression in your ERB will be parsed as subtracting the value of the date variable from the result of a call to the start() method of the position object. Hyphens aren't valid in identifiers within Ruby.
I'm not familiar enough with the LinkedIn gem to suggest a solution, except to say that since it's based on an XML API, you should look for a way to manually pull data out of a tag pair. Most similar gems offer such a method. Also, this is a great case for using IRB as an exploratory tool: fire up an IRB session and see what happens when you call position.methods, after properly creating the position variable of course. My guess would be that you'll see something in that list which suggests an answer.
Looks like it returns a Hashie::Mash which converts keys, with a few extra rules:
https://github.com/pengwynn/linkedin/blob/master/lib/linked_in/mash.rb
You said you'd already tried position.start_date right? That should work. But if not, have you tried position['start-date'] or position['start_date'] one of those two should also work, since it's a Mash.
Related
so basically I have a bunch of HTML strings in a MySQL table and I am trying to display then through EJS.
For instance, I have a string that looks like this is a link with some <code>code</code> next to it. In my code I try to display it in that way.
<%- listOfStrings["myString"] -%>
However, as you probably guessed when reading the title, the string seems to be escaped when displaying on the screen.
What's even weirder to me is that I have two tables with such strings, and it works for the first one, while it doesn't for the second one. One difference though, is that the first one is hardcoded, while the second one can be edited through some tool on my website. Encoding is utf32_unicode_ci for both tables, if that matters.
For debugging purposes I tried to store the aforementioned strings in a js variable and display them in the console: then it seems like <and > characters are all escaped for some reason. Is there an explanation to this behavior, and if so how to fix it so that HTML renders correctly?
Thanks for your help!
You can try it :
<%=listOfStrings["myString"]%>
Been scratching my head for a while on this one and despite trying many variations I cannot see the mistake. After writing the app file, which contains what looks like the correct DataMapper.setup code for using PostgreSQL (?), and upon trying to play around in IRB/PRY, i just get a 'FATAL database not created' message even after i have called 'Song.auto_migrate!', here is my code, can anyone help me get past this? Thanks in advance:
require 'data_mapper'
require 'dm-core' #main DataMapper gem
require 'dm-migrations' #extra DataMapper functionality extension
DataMapper.setup(:default, "postgres://localhost/development")
class Song
include DataMapper::Resource
property :id, Serial
property :title, String
property :lyrics, Text
property :length, Integer
property :released_on, Date
end
DataMapper.finalize
I require the file all fine in irb, then call Song.auto_migrate! and it runs the 'database does not exist' error. What am i doing wrong?
You need to do this in command line:
psql
and then
CREATE DATABASE development;
before even trying to run Data Mapper setup code.
Perhaps you are missing this line: DataMapper.auto_upgrade!
On a side note, remember that auto_migrate! will wipe any existing data, whereas auto_upgrade! doesn't: http://datamapper.org/getting-started.html
I'm using the texticle gem in a Rails 3 app.
I've got a table full of food names, such as Onion, Green Onion, Onion Powder, etc. etc.
I'm searching the table with
foodnames = FoodName.search(params[:search])
return render :json => foodnames
when I attempt to search for 'chopped onion', I had hoped to get back a list of matching 'onion', as those are somewhat close, but I'm getting an empty set.
If I use just 'Onion' or 'Onions', I get back the list I expected.
there seem to be conflicting documentation with texticle.
the github repository page, https://github.com/texticle/texticle shows methods like fuzzy_search, but when I try to run that I get undefined methodfuzzy_search' for #Class`
the other documentation http://texticle.github.com/texticle/ says nothing about fuzzy_search or similar capabilities.
my gem file has gem 'texticle', '~> 2.0', require: 'texticle/rails', though I did add that in and re-bundle install after I original had it without the version or require statements.
can anybody clarify what is going on here, and how I can get a better search result? It seems far too strict for my needs as is, and I suspect things are not working as they are supposed to.
Using the rally-api I have been trying to access the portfolio kanban state value of items eg.
features.each do |feature|
puts feature.State # also tried feature.State.Name
...
end
But this always return an empty string.
this looks to be a back end WSAPI change that is coming. PI states are going to become readable via the wsapi in 1.37, but they are not currently returned when you query for Portfolio Items. When wsapi 1.37 comes out, if you pass :version => 1.37 to the config to rally_api, you should then be able to get it in the fetch string.
It is easily accessed by using "feature.State.Name". However, in the Ruby toolkit, these fields are all lowercase, with Pascal-cased field names using underscores(_) to represent the casing. It should be, in this case:
put feature.state.name
and in a more complex case (PlannedRemovalDate):
put feature.planned_removal_date
Hope this helps.
Did someone try to integrate puret into rails_admin? I can't make a language switch to edit different translations :(
Changing I18n.locale forces whole rails_admin to use specified locale.
Now I got the solution. The two can work together well. In short:
Delete the pureted column(s) in your model
If you have the column pureted still in your model, rails form helper will bypass puret. That is, if a model called Post has a field called contents to be i18ned, the table posts SHOULD NOT have the column contents.
Actually we should use globalize3 instead. With this you do not need to remove the original column. And puret doens't support nested attributes assignment. globalize3 works very well.