Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
1 Post

I'm trying to do a simple general form creator where i can just specify the table to create the form for, the controller/action wich will handle the submit and a small title, so far it works great, but only adds textfields.

My question is, is there a way to know if a column is a foreign key (other than checking if the field ends with '_id'. I want this so if the field is a foreign key i can present a drop down menu from the other table instead of the text field.

So far i have this...


class SharedController < ApplicationController def form_for

@for = params[:locals][:for].camelize.constantize.new
@cols = params[:locals][:for].camelize.constantize.column_names
@ctrl = params[:locals][:ctrl]
@action = params[:locals][:action]
@title = params[:locals][:title]

end end

The view is actually a partial and looks like this

{ :controller => @ctrl, :action => @action } do |f| %>

  <br />

And a example call to it is

'form_div', :url => { :controller=> 'shared',:action => 'form_for', :locals => { :title => 'Idioma Nuevo', :for => 'language', :ctrl => 'params',:action => 'save_language', }})%>

wich in that case will put the partial on a div.

any help would be apriciated, or comments on the way i'm doing this, first time using rails ^^

1 Post
Login to add your message