How to name the table, rails class
Your MySQL Database need a table named my_stories, note that: Not mystories, not my_story, and mapping class shocould named mystory.
Rails Ajax
It's very simple Using ajax on Rails Web application.
1. Using link_to_remote
<Head>
<% = Javascript_include_tag "prototype" %>
</Head>
<% = Link_to_remote ("Click here ",
: Update => "time_div ",
: URL =>{: action =>: say_when },
: Position => "after") %>
<Div id = "time_div">
2. Using form_remote_tag
<Head>
<% = Javascript_include_tag "prototype" %>
</Head>
<% = Form_remote_tag (: update => "my_list ",
: URL =>{: action =>: add_item },
: Position => "TOP") %>
New item text:
<% = Text_field_tag: newitem %>
<% = Submit_tag "add item with Ajax" %>
<% = End_form_tag %>
<Ul id = "my_list"> </ul>
3. Using observers
Make an Ajax call to an Action Handler whenever the value of the field changes.
<Head>
<% = Javascript_include_tag "prototype" %>
</Head>
Live Search: <% = text_field_tag: searchtext %>
<% = Observe_field (: searchtext,
: Frequency => 0.25,
: Update =>: search_hits,
: With => "searchtext ",
: URL =>{: action =>: live_search}) %>
<P> Search Results: </P>
<Div id = "search_hits"> </div>
Validation
In model class just add like this
Validates_presence_of: title,: image_url
Validates_numericality_of: Price
Validates_uniquenss_of: Title
Validates_format_of: imageurl,
: With => % R {^ http:. + \. (GIF | JPG | PNG) $} I,
: Message => "must be a URL for a GIF, JPG, or PNG Image"
Cycle
For product in @ Products
End
@ Products. Each do | product |
End