Hi,
I am trying some development for rails but I've run into a few issues. I am using Instant Rails 2.0 (Rails version 2.0.2, Ruby version 1.8.6)
First, the scope of variables.
I have a page set up which is intended to display new information as it is added to the database table.
This code always updates with all the items in the database, as if the @newest_id wasn't being checked at all. Where should the id be stored, on the client? How can it be updated while a user views, but reset when the user returns or manually refreshes (F5) the page?
Second, I am attempting to allow tags on the pieces of content, however I want to try implement them myself with only basic functionality.
I have the following tables:
tag(id, name)
content_tag(tag_id, content_id)
content(id, title, image_url, image_text)
Pseudocode would be something like this, though I don't know how to implement it into Rails.
Third, I have to implement a search function. Is it possible to use auto_complete plugin to search through multiple tables for results to return in the auto_complete? For example autocomplete in a single search box on tag(name) and content(title).
I am trying some development for rails but I've run into a few issues. I am using Instant Rails 2.0 (Rails version 2.0.2, Ruby version 1.8.6)
First, the scope of variables.
I have a page set up which is intended to display new information as it is added to the database table.
Code:
[i]content/view.html.erb[/i]
<%= periodically_call_remote(:update => "content", :frequency => 1, :position =>
"bottom", :url => {:controller => "content", :action => :get_new, :id => @content.id }) %>
Code:
[i]controllers/content_controller.rb[/i]
before_filter :get_id
#gets all the content with an id greater than the current id, reset id
to newest
def get_new
@content = Content.find_all_by_id(params[:id], :order => "id DESC",
:conditions => ["id > ?", @newest_id] )
@newest = Content.find(:first, :order => "id DESC")
@newest_id= @newest.id
end
#get the first id, so that all comments are retrieved on first call
def get_id
@newest = Content.find(:first, :order => "id ASC")
@newest_id= @newest.id
end
Second, I am attempting to allow tags on the pieces of content, however I want to try implement them myself with only basic functionality.
I have the following tables:
tag(id, name)
content_tag(tag_id, content_id)
content(id, title, image_url, image_text)
Pseudocode would be something like this, though I don't know how to implement it into Rails.
Code:
1. Parse the input from content_create view
2. Insert content into table
3.1. parse tags (strip by spaces, allow only 5)
3.2.1. for each tag
3.2.2. check for existence/uniqueness of name in tag table
3.2.3. if it doesn't exist, add it, otherwise do nothing
3.2.4. add tag_id and content_id into the content_tag table
3.2.5. end for loop
4. end
Third, I have to implement a search function. Is it possible to use auto_complete plugin to search through multiple tables for results to return in the auto_complete? For example autocomplete in a single search box on tag(name) and content(title).