Hi , I am new to Ruby on rails..
I am trying to write a sample ruby code for the action that i having in my api Blogs.
def tag
@query_string = "Blogpost.published"
if params[:limit]
if params[:limit].to_i.class == Fixnum
if params[:limit].to_i > 0
@query_string += ".limit(#{params[:limit]})"
end
end
end
@query_string += ".find_tagged_with(\"#{params[:tag]}\")"
@blogs = eval(@query_string)
respond_to do |format|
format.html { redirect_to root_path }
format.xml { render :xml => @blogs.to_xml(to_any_options) }
format.json { render :json => @blogs.to_json(to_any_options) }
end
end
The above is my action tag ..
I am having some 3 tables .. 1. Blogpost which stores all the blog details .. 2. Tags - Each blogpost have some tags associated with it . those tags are stored in the Tags table with (id,tagname) 3. Tagging which contains the (id,tag_id,taggable_id) where tag_id is the id for the tagname from Tags table and taggable_id is the id for the BLog to which this tag is associated..
I will run the link by giving
/api/blogs/tag/.xml
which returns all the blogposts linked to the tag..
I want to write Ruby code for the same.. How to write so ??
Please give me suggestions..