I am just looking at creating an API for our clients to interact with our main Rails 3 application.
On the one hand, I wanted the json response to contain some form. Basically, the code of some form, which we control and display on their website.
This works fine for me (simplified):
def login_form @response = Form.find_by_something(params[:something_else]) if @response render :status=>200, :json=>{:response => @response} end end
And on the client side, I can get:
@logins = HTTParty.get("#{set_auth_url}/api/v1/logins.json?auth_token=xyz&something_else=abc").parsed_response
And display the form
= @logins["response"].html_safe
The problem is that the form code has some dynamic variables:
For instance:
<div class="login"> <FORM name="form1" METHOD="get" action="<%= request.path %>?"> <INPUT TYPE="HIDDEN" NAME="chal" VALUE="<%= params['challenge'] %>"> <% if @current_location['success_url'] %> <INPUT TYPE="HIDDEN" NAME="userurl" VALUE="/success"> <% end %> <input type="hidden" name="UserName" placeholder="Username" value="<%= @user['username']['username'] %>"> <input type="submit" name="login" value="Login" class="btn"> </div>
I wonder is this a good idea? And if so, how can I break these variables in html ??
If this is not the case, someone could recommend a more convenient way to do it.
source share