How to create a post from iPhone to Rails - iphone

Newbie to Rails and iOS here. I have a Rails blog application with Post model that has just a title and and image. I can create a new Post from a browser using the following html.erb code:
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<p>
<%= f.file_field :image %>
</p>
<div class="actions">
<%= f.submit %>
</div>
But how would I do this from an iPhone app? Is there an equivalent form function in iOS?

I can recommend you using ASIHttpRequest, especially the class ASIFormDataRequest. With this you can send form data easily as a POST request.

Related

How to use bootstrap dropdown in creation forms?

I don't know how I can satisfy connection with database.
Now I have this code in my _form:
<div class="field">
<%= f.select :language, options_for_select(%w[English Chinese Ukrainian]) %>
</div>
How I can do it with bootstrap or how I can make it look like bootstrap ?

Fire ASP.NET MVC2 client side validation from an anchor tag

I'm changing an existing ASP.NET MVC2 application which uses the MicrosoftMvcValidation.js etc. for client side validation.
<h2>Details</h2>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Details", "Add", FormMethod.Post, new { id="addForm" }))
{ %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Title) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Title) %>
<%: Html.ValidationMessageFor(model => model.Title) %>
</div>
...
<input type="submit" value="Create" />
The client side validation is working fine and dandy.
However, the designer wants to change the submit button to be a pretty anchor tag. I'm trying to submit the form using the anchor's onclick event i.e:
<a class="add-campaign-button-done" onclick="document.getElementById('addForm').submit();"><span></span></a>
The form submits, but client-side validation no longer works.
With a little bit of jQuery you can do the trick, see this post : Call MVC 3 Client Side Validation Manually for ajax posts for more informations and let me know if you need more help!

How can I get data from input fields that are on master page?

I'm using ASP.NET MVC 2 technology for developing my web site. I have two input fields in my master page (username and password) and one submit button.
How can I get data from those input fields?
Please help.
You should probably start at this page
When the form is submitted, it should direct to a server-side page that will process the data.
Check out Read Post Data submitted to ASP.Net Form for some details on reading the data with that server side page.
MasterPage:
<asp:TextBox id="txtUsername" runat="server"></asp:TextBox>
Content Code Behind:
string username = ((TextBox)Master.FindControl("txtUsername")).Text;
I found what i was looking for. Thank you for your answers.
<% using (Html.BeginForm("LogOn", "Account", FormMethod.Post)) { %>
<%= Html.LabelFor(d => d.UserName)%>:
<%= Html.EditorFor(d => d.UserName)%>
<%= Html.LabelFor(d => d.Password)%>:
<%= Html.Password("Password")%>
<input type="submit" value="Login" />
<%= Html.ValidationSummary() %>
<% } %>

ASP.NET MVC2 DataAnnotaion Validation within an updatepanel

I am currently working on a website using MVC2 and using ASP.NET Ajax to handle moving between pages. Everything is working fine except a page that has a form for the user to fill out that uses DataAnnotations for validation. This form falls within my UpdatePanel and won't conduct server or client side validation, both which I have working if I remove the UpdatePanel.
Is this even possible, or am I missing a step?
Here is a general outline of my code:
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptMgr" runat="server" ScriptMode="Release">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<div class="page">
<div id="main">
<% Html.EnableClientValidation(); %>
<h2>
ContactUs</h2>
<% using (Html.BeginForm())
{%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Name) %>
<%: Html.ValidationMessageFor(model => model.Name) %>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Take a look at Ajax.BeginForm instead of using the update panel.

How to include the login form on the Home index page in MVC

I really need your help for this. I am relatively new to programming and I need help to something that could be easy for a experienced programmer.
I would like to get the login form that we get for free in an MVC application on the left sidebar of my Home index page instead of the usual Account/Login page.
I am facing some problems.
First I need a product object to be displayed on my Home Index page as well.
What I did is that I added a product object to the LogOnModel that they provide in the AccountModels class and I created a UserControl (partial view) copying the content of the LogOn.aspx view. Now my Home index.aspx as well as my partial view inherits the LogOnModel class.
I can see the Login form on my Home Index page as well as my product object BUT the login Form is never empty. The last username and password always appear there.
I know I must have forgotten something or have done something wrong or the way did it is completely wrong !!
Please could you give me some advice
Thks
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CoderForTradersSite.Models.LogOnModel>" %>
<h4>Login Form</h4>
<p>
Please enter your username and password. <%= Html.ActionLink("Register", "Register") %> if you don't have an account.
</p>
<% using (Html.BeginForm()) { %>
<%= Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") %>
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
<%= Html.LabelFor(m => m.UserName) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(m => m.UserName) %>
<%= Html.ValidationMessageFor(m => m.UserName) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(m => m.Password) %>
</div>
<div class="editor-field">
<%= Html.PasswordFor(m => m.Password) %>
<%= Html.ValidationMessageFor(m => m.Password) %>
</div>
<div class="editor-label">
<%= Html.CheckBoxFor(m => m.RememberMe) %>
<%= Html.LabelFor(m => m.RememberMe) %>
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
<% } %>
2 things to consider here..
1) You didn't have to mix the product and logon models.. Have the login form in a partial view, and create an action in the Account controller that will return the partial view:
public ActionResult LogonModule()
{
return PartialView();
}
Then on your Index page, use the following snippet to display the logon panel: <%: Html.RenderAction("LogonModule", "Account") %>
This way this panel will be completely independant from the main page model. It will add the logon module server-side, so it's completely transparent to the user.. The generated html is absolutely the same.
2) You're saying that the login/password fields are prepopulated. Are you completely sure that it's not the browser populating these fields? Most browsers do this, and it can lead to a lot of confusion :)
Check the html. If the login and password are not there - then you're fine ^_^
Start by learning how it is working. What is the M, the V and the C, and how you make them communicate. If you just take the starting solution and start adding a bunch of stuff on top of it without thinking, your app will be a mess pretty quickly.
Adding a product to the LogonModel doesn't make sense for example. You should create your own model for the product and create a strongly typed partial view or a DisplayModel for it to be able to display it easily.Create new ViewModel for your pages that contains the right elements of your page and name them with something that makes sense to you.
You could start here for example :Build Your First ASP.NET Application with ASP.NET MVC