-1

In my ruby on rails application, I want to get controls value into controllers page:

    below is view page:
<%= form_for :managerviewresume, :url => { :method => :post, :action => :managerviewresume }) do |f| %>
        <table class="table" width="100%">
            <tr>
                <td><%= @selection %></td> //Here I am checking radio button value
                <td>
                    <label style="font-size:small;">Selected?</label>
                    <label class="radio inline" style="font-size: small">
                    </br>&nbsp;&nbsp;&nbsp;
                    <%= f.radio_button :select, "Yes", :id => "rb_select1" %>
                    Yes
                    </label>&nbsp;&nbsp;
                    <label class="radio inline" style="font-size: small">
                    <%= f.radio_button :select, "No", :id => "rb_select2" %>
                    No
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <%= f.submit "Save", { :class => "stylbutton" } %>
                </td>
            </tr>
        </table> 
    <% end %>

below is controllers page:

class ManagersController < ApplicationController
  def managerviewresume
    @selection = params[:select]
    render "managerviewresumes"
  end
end

In the controller's page I am getting below error at this line render 'managerviewresumes' :

Missing template managers/managerviewresumes, application/managerviewresumes with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "C:/Sites/VideoResume/app/views" 

below is the route:

  match '/managerviewresumes',  to: 'managers#managerviewresume', via: 'get'

Kindly suggest what should I do get radio button value from view page into controller page. waiting for reply. Thanks.

user88
  • 1,174
  • 3
  • 27
  • 51
  • 1. inspect the params 2. error is clear `Missing template ...` – Nithin Jun 27 '14 at 06:47
  • First I want to check params get value correctly from view page into this variable `@selection` that's why I am doing this `<%= @selection %>` into the view page – user88 Jun 27 '14 at 06:52
  • use `puts params.inspect` in your `action` and check the `log` – Nithin Jun 27 '14 at 06:54
  • can you specify the action and method thier? I think it will resolve your problem actually its not geeting what type of request is .e.post or get – Deepti Kakade Jun 27 '14 at 06:56
  • my post is working fine when I remove this `render "managerviewresumes"` from controller page, but I want that whan i click on radio button, the radio button value show into the `managerviewresumes` page at this line `<%= @selection %>` – user88 Jun 27 '14 at 09:54

1 Answers1

1

Render

Firstly, you don't need to use render to render the same view as your action name

When using a Rails controller, you can call this without issue:

#app/controllers/your_controller.rb
Class YourController < ApplicationController
   def your_action
       #-> will automatically render the "your_action" view
   end
end

So I would remove your reference to the render action (as it is an unnecessary step). This will not resolve the issue directly, but should ensure your application is more convention over configuration

--

Routes

Secondly, you may need to look at resourceful routing

In Rails' routing structure, you are able to call resources :controller to generate a series of RESTful routes:

enter image description here

I understand you likely want to keep using your action, but for the sake of correctness, can I recommend you look into your config/routes.rb file & ensure you're using as many resource-based routes as possible:

#config/routes.rb
resources :managers do
   collection do
       post :managerviewresume
   end 
end

--

Form

Finally, I think your form needs to be improved

You're using form_for, which is mainly for ActiveRecord objects (if you want to create new record etc. It seems you'll be better suited to using form_tag instead:

<%= form_tag managers_managerviewresume_path do %>
    <table class="table" width="100%">
        <tr>
            <td><%= @selection %></td> //Here I am checking radio button value
            <td>
                <label style="font-size:small;">Selected?</label>
                <label class="radio inline" style="font-size: small">
                </br>&nbsp;&nbsp;&nbsp;
                <%= radio_button_tag :select, "Yes", :id => "rb_select1" %>
                Yes
                </label>&nbsp;&nbsp;
                <label class="radio inline" style="font-size: small">
                <%= radio_button_tag :select, "No", :id => "rb_select2" %>
                No
                </label>
            </td>
        </tr>
        <tr>
            <td>
                <%= submit_tag "Save", { :class => "stylbutton" } %>
            </td>
        </tr>
    </table> 
<% end %>

This syntax might need checking, but this will send the :select params as required, which is not what your current form will be doing.

This should be coupled with a views/managers/managerviewresume.html.erb file for Rails to load

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • your post is working fine but when i click on radio button `No` it show me this `{"No"=>"{:id=>\"rb_select2\"}"}` and when I click on radio button `Yes` it show me this `{"Yes"=>"{:id=>\"rb_select1\"}"} ` and I want to get only `No` and `Yes`. – user88 Jun 27 '14 at 10:16
  • I think that's to do with the syntax of the [`radio button`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-radio_button_tag) itself - you'll be best doing this: ```radio_button_tag("No", "0", false, id: "rb_select1" )``` – Richard Peck Jun 27 '14 at 10:19
  • I think you'll have to include a `label` like this: http://stackoverflow.com/questions/746387/labels-for-radio-buttons-in-rails-form - you might be best using [label_tag](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-label_tag): `<%= label_tag 'rb_select1', 'No' %>` – Richard Peck Jun 27 '14 at 11:33
  • I am using this `<%= radio_button_tag :select, "Yes", :id => "rb_select1" %>` from your post and its working fine but why it checked on `No` radio button and when I check on `Yes` radio button and click on save button, the page refresh and radio button `No` is checked. why? – user88 Jun 27 '14 at 11:36