July 26, 2007
Today i’ve been helping the wive with her data: she’s trying to do a big text import into a mysql database and there just seem to be constant problems. She was originally doing it via the heidisql front end but it was still going after 2 days, so was obviously screwed. So, killed that, now trying to do it via the command line, with the mysqlimport command. Getting this error message “lock timeout exceeeded”. This was clearing the data out of the db first. Went into mysql and tried to just delete all the data with “delete from tablename” and get the same lock timeout problem there.
Everything’s just such a massive complicated pain in the arse at the moment, i can’t seem to make anything work. It’s really disheartening.
Looking up the ‘accessing the iframe title’ problem again, i came across this bit of info:
“An error of access denied or permission denied will be triggered if you try to access properties of the document loaded into the iframe or its window if that document is from another domain.”
That’s the problem i’ve been having – access denied! But that means i can never get the title out of an iframe – what’s the point of this security? arggghhhhhhhhhh.
This resource seems pretty useful – http://www.dyn-web.com/dhtml/iframes/
Anyway, giving up (for real this time) on the ‘add this page to newspipe’ link. I’ve deleted the link as well. Going to get back to the business of adding links. I’ve decided that the links should simply be saved as articles with a score of 0, which means that the definition of an article is now simply anything with score > 0. I’ll need to make some slight alteration to the list page to take this into account.
Got this all sorted out thanks to an incredible handy forum thread that was pointed out to me. Basically, instead of linking articles directly to themselves, i link articles and “links”, where a link is really an alias for an article. Steps –
Make a new DB table called articles_links which has article_id and link_id. Put some sample data in for testing.
Then, in models/article.rb, add a habtm relationship, setting the following parameters (note the commas):
:class_name => “Article”, #tell rails that the class of ‘link’ is “Article”, ie specify the alias
:association_foreign_key => “link_id”, #tell rails what the foreign key in the join table is
:join_table => “articles_links” #tell rails what the join table’s called
That’s all displaying nicely (well, could do with a bit of stylesheet action but that’s easy). Next step is to make the ‘add a link’ link work.
Done this, not working right though: I added a new method to the controller:
@link = Article.new
This calls the new_link view, which is pretty much the same as the ‘new’ view used to make a new article – it calls the same form, and passes the data through to another controller method:
@link = Article.new(params[:article])
if @link.title == “”
@link.title = (Hpricot(open(@link.url))/”title”).first.inner_html
@link.added_at = DateTime.now.to_s
@link.user_id = session[:user].id
@link.points = 0
flash[:notice] = ‘Link was successfully created.’
redirect_to :action => ‘show’, :id => params[:id]
render :action => ‘new’
Now this isn’t using DRY very well – i should come up with a way to combine this and ‘create’, which is virtually identical. But i wanted to get it working before trying anything clever.
Problem – this isn’t making a new link, it’s only making a new article (which is fine in itself) but it needs to make a link entry in the join table as well. Another problem is that i want to redirect to the show page for the original article, ie that this link belongs to. OK – need to look at making a comment for this – it’s like a comment in that we need to pass through the original article id to use when making the comment.