You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using rails form helper with one model's data on several controllers/views. Like let's say I have a comments model and use comments at many occasions.
In this particular case I am using several forms in an admin namespace. With normal select fields I have a working solution but I don't know how to access the correct data. As I don't have too much Rails experience right now I am stuck. That's why maybe someone here can help me out.
In my example I am using a form for a @gallery on a foreign admins controller. In the form right now I let editors chose which @game belongs to a @gallery. Like so:
<%= form_for(@gallery) do |f| %>
...
<%= f.select :game_id, options_for_select(@games.map {|g| [g.name, g.id]}) %>
...
<% end %>
If I use <%= f.autocomplete_field :name, autocomplete_name_games_path %> instead it tells me, that :name is not available with my @gallery object, which is true, but I thought I could use the autocomplete of the games controller at this place, too.
Kind regards
The text was updated successfully, but these errors were encountered:
You should be able to. For example, I have a user form that has an address field for "state". But I have created only a model that interacts with a table of states in the database but I can use those states in any controller using this autocomplete function. So I setup autocomplete in the user controller to look at the states model.
In your example, you would need to setup the autocomplete in the foreign controller but where you may be confused is that you don't need that autocomplete_field to be :name in order to use the name data for the autocomplete. You would then have something that looks like so:
In your foreign controller:
autocomplete :game, :name
Then in the form:
<%= f.autocomplete_field :game_id, autocomplete_game_name_foreigncontrollernames_path %>
The field would autocomplete on the game names but then you will run into the same issue I'm having where the reality is you need the form to save the game_id and not the name and I'm still working on figuring that out since I want the autocomplete to show the full state name but save the two letter abbreviation instead. :)
I am using rails form helper with one model's data on several controllers/views. Like let's say I have a comments model and use comments at many occasions.
In this particular case I am using several forms in an admin namespace. With normal select fields I have a working solution but I don't know how to access the correct data. As I don't have too much Rails experience right now I am stuck. That's why maybe someone here can help me out.
In my example I am using a form for a
@gallery
on a foreign admins controller. In the form right now I let editors chose which@game
belongs to a@gallery
. Like so:If I use
<%= f.autocomplete_field :name, autocomplete_name_games_path %>
instead it tells me, that:name
is not available with my@gallery
object, which is true, but I thought I could use the autocomplete of the games controller at this place, too.Kind regards
The text was updated successfully, but these errors were encountered: