Please get the post from here moved because of the formatting problem.
Read more!
Posted by Rahul 0 comments
Labels: Ruby on RAILS, updating a record in the database using form_for
This post will be of use to you only if you happen to be a newbie to Ruby and Ruby on Rails and currently working on the Shovell web application from the book "Build Your Own Ruby on Rails Web Applications" by Patrick Lenz.
This post will be helpful to you if you are trying to add a feature to the Shovell application where the users of the Shovell should be able to update/edit stories posted by them.
After completing the Shovell application as guided in the book "Build Your Own Ruby on Rails Web Applications" I wanted to add edit functionality to my stories of Shovell application and after a few hours of struggle (I am very new to Ruby and Ruby on RAILS RoR) I was successfully able to implement the edit functionally to Shovell's stories.
This is how I achieved it :)
--Display a "edit story" link next to the "Submitted by" link on the show story page.
(validation done: dispaly the "edit story" link only if the current story being displayed is submitted by the current logged in user.)
Add this portion of the code to your /views/story/show.rhtml file within the submitted_by class
<% if logged_in? %> <% if @story.user.login.to_s == @current_user.login.to_s %> <%= link_to 'edit story', :controller => 'story', :action => 'edit_story', :id => @story %> <% end %> <% end %>
The submitted_by class after adding this code looks like this
Submitted by: <%= link_to @story.user.login, :controller => 'account',:action => 'show', :id => @story.user.login %>
<% if logged_in? %> <% if @story.user.login.to_s == @current_user.login.to_s %> <%= link_to 'edit story', :controller => 'story', :action => 'edit_story', :id => @story %> <% end %> <% end %>
--Once the user clicks on the "edit story" link, take him to /views/story/edit_story.rhtml page pre-filled with all the story details and tags. Allow user to make changes and save the updates.
Create a new file named edit_story.rhtml in /views/story/ and add the following code to it.
<%= error_messages_for 'story' %>
<% form_for :story do |f| %> Title of the story:
<%= f.text_field :name %> link:
<%= f.text_field :link %> Description:
<%= f.text_area :description %> Tags:
<%= text_field_tag 'tags', @story.tag_list %> <%= submit_tag %> <% end %>
Add the following code to your story controller named story_controller.rb located in /controllers/story_controller.rb
def edit_story @story = Story.find(params[:id]) @story.user = @current_user if request.post? and @story.update_attributes(params[:story]) @story.tag_with params[:tags] if params[:tags] flash[:notice] = 'Story was successfully updated.' # redirect_to :action => 'edit_story' end end note: this controller part of the code should be added anywhere above the protected section.
All the code above looks self explanatory but in case you have a question please leave a comment.
Other questions that got answered by this post:
1.How to use form_for to update data in the the database in Ruby On RAILS. 2.How to use form_for to update a record in the database in ROR.
3. What method to use to update a records in the database using Ruby on RAILS.
(hint: @story.update_attributes(params[:story] )
4. How to fetch all the values of tags from a the current story and set it as value of the text_field_tag (hint: <%= text_field_tag 'tags', @story.tag_list %> )
Posted by Rahul 0 comments
I just received a beta invitation to try out the Xcerion XIOS (XML based Internet Operating System). To learn more about Xcerion XIOS visit this page on wikipedia : http://en.wikipedia.org/wiki/Xcerion_XIOS
Visit this link : http://xcerion.com/screenshots/ fro a detailed intro of Xcerion XIOS
Currently this Internet Operating system is supported by on IE6+ but they have Firefox support on their top priority list.
Be the first few to try it, drop me a line with your email address if you would need an invitation :)
Posted by Rahul 2 comments
With the help of WWIGO (Webcam Whereever I Go) software available free of cost from http://www.motvik.com/ it's simple to use your camera phone as a webcam.
WIWIGO is a free software that allows you to use your camera mobile phone as a webcam over the bluetooth connection between the mobile phone and the computer. It gives better video quality than any average webcam, is compaitable with all applications that you would generally use your webcam for and if FREE.
All you need is a camera phone with bluetooth, a desktop or laptop with bluetooth and WWIGO s/w on your mobile and computer.
To know more about WWIGO go to about WIWIGO page here : http://www.motvik.com/about-wwigo.php
To see a list of supported camera mobiles that can be used as a web camera with the help of WIWIGO s/w and to download WIWIGO "mobile camera/webcam" software visit this page : http://www.motvik.com/download.php
Posted by Rahul 1 comments
You can call him blogging Guru, the first professional blogger of India, Amit Agrawal who runs his blogs at http://labnol.blogspot.com and http://www.labnol.org is going to share his wisdom at BarCamp3 Delhi on 8th of Dec 2007, I wish I could have written it a little in advance and made the message reach a few more readers of my blog.
Watch these videos to and you will know what I am talking about.
Amit Agrawal featured on CNN-IBN
Amit's life journey as a blogger.
To know more about Amit visit his personal page at: http://www.labnol.org/about.html
If you are a blogger and you can make it to Delhi by tomorrow, this is the session you will never want to miss. If anyone can do a favor to video record his session and share it, it will be a great help to the whole blogging community :)
Posted by Rahul 1 comments
Here is the news that came on www.tech2.com today about the launch of digital photo frame in India by Transcend . The price of the digital photo frame launched by Transcend in India as mentioned on www.tech2.com news post is Rs. 5500. You can read the full full story on www.tech2.com website link given below.
http://www.tech2.com/india/news/general/transcend-launches-digital-photo-frame-in-india/23145/0?utm_source=dailynewsletter&utm_medium=email
If you are a regular reader of my blog you might remember my post about affordable digital photo frame available on www.futurebazaar.com, the post is still available at this link http://tpops.blogspot.com/2007/10/affordanle-hi-tech-digital-photo-frame.html
After reading about the launch news on tech2 I was surprised to see the price tag Rs. 5500 , I remembered that the digital photo frame that I had mentioned in my post was available for only Rs. 3999. So, I went back to my post and clicked on the link to the product purchase page to see if the product is still available and to my surprise the digital photo frame is still available for sale on futurebazaar website for Rs.3999.
In my opinion Rs.3999 is pretty reasonable price for a digital photo frame and I would not want to spend Rs.5500 if the same product with all the same features is available for just Rs.3999.
Posted by Rahul 3 comments
Currently channel V India is showing this tv commercial(watch the commercial below,caution: NSFW, NSS content) to promote its contest "India's Hottest".
If you are done watching the commercial ;), you would have realized that you don't hear "www.indiahottest.in" anywhere in the commercial or maybe I missed the name of the website in the commercial. I am assuming that a large percentage of viewers like me will miss the official domain name of this contest and as a general tendency if they want to explore about the contest a little more, they will do what I did, they will type www.indiashottest.com and unfortunately will land up on this adult/porn site named "www.indiashottest.com", the site looks like this(see the picture below, this picture has been blurred and cut short to not to display p*** content and links).
Whereas the intention of the commercial was to promote "India's Hottest" contest and direct all it's users to "www.indiashottest.in".
The official site for the "India's Hottest" contest of channel V India is "www.indiashottest.in" and it looks like this (the picture below).
Owners of www.indiashottest.com must be celebrating this huge amount of sudden free traffic. Great free promotion!!!
Posted by Rahul 5 comments
If you are a new phpmotion video sharing script package admin and have no clue about how to replace the default website logo as seen in the picture below
to your own customized logo that reflects your site's business brand, something like the one you see in the picture below
All you have to do is create your own logo file, name it "phpmotion.gif" and replace the default phpmotion logo file named "phpmotion.gif" with your logo file.
The default phpmotion logo file "phpmotion.gif" is located in /phpmotion/images/ directory of your phpmotion installation.
One thing that you need to keep in mind that these file names are case sensitive if your installation is running on linux server.
Important--Please remember to even have the filenae extension in smallcase letters. So, the right filename would be "phpmotion.gif" and any file name like "phpmotion.GIF" or "PHPMOTION.gif" etc.. would not work if you are running your phpmotion video sharing script installation on a linux server.
Posted by Rahul 12 comments
If you are a phpmotion video sharing script administrator and want to change the default logo "LOGO" of the video player, as seen the picture below to
your own customized logo, as seen in the picture below,
All you have to do is:
replace the default logofile of phpmotion named "playerlogo.png" with your own logo file. The logo file "playerlogo.png" is located in /phpmotion/image_s/ of your phpmotion installation directory.
Steps to change the default video player logo of phpmotion video player would be:
-- your own customized logo for for your site named "playerlogo.png".
-- to the directory /phpmotion/image_s/ of your phpmotion installation and delete the default "playerlogo.png" file.
-- your logo file to the same location /phpmotion/image_s/
Posted by Rahul 1 comments
On many occasions I felt the need to use "Google Transliterator" just to convert all my Hinglish typing to Hindi so that I could copy and paste the Hindi output and use it anywhere I wanted.
Unfortunately I don't see any independet service for "Google Transliterator" like the one we have for Google Translate :(। But here is an easy way to use "Google Transliterator" without the hassle of using orkut's or blogspot's Transliterator feature. For this to work you must be a iGoogle user.
Go to this link: http://www.google.com/transliterate/indic/about.html
look for something that looks like this...
Click on the the "Add to Google" button on the page on the above link and follow from there. You will find that link on the bottom of the above mentioned page.
Or, just click on the "Add to Google" button below and follow from there.
This is a one time work and will save you a lot of frustration everytime you need to convert your Hinglish to reusable Hindi using "Google Transliterator".
This is the complete post here, you wont get anything more by clicking on the the "Read More" link below :).
Type rest of the post here
Posted by Rahul 0 comments