Rails 3.1.3

I am not sure Rails can do what I want to do.

I have a form for update like,

<%= form_for script, :remote => true do |f| %>
<%= f.hidden_field :video_id %>
<%= f.text_field :startp, :readonly => true %>
<%= f.text_field :text %>
<%= f.submit "update" %>
<% end %>

then, JavaScript (jQuery) inserts a value for 'startp' and for 'text' in
to the 'text_field' .
Of course, this set of values is already stored in DB. I want to update
it after editing it.

This form gives an error

undefined method `model_name' for NilClass:Class

whose I assume the cause is the nil object 'Script'. The object is not
properly passed.

I try to render this form like following.

<%= render :partial => "update_script",:locals => { :script =>
Script.find_by_startp(params[:startp])} %>

Since 'startp' is readonly and users should be able to edit only 'text',
I hoped to associate the 'text' with 'startp' rather than 'id' of
'script'.

Is there anyway to pass the obejct?

It is very difficult to explain the situation. But if someone can guess
the problem and have some suggestion, I would appreciate it.

Thanks .

soichi

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Peter Vandenabeele at Feb 18, 2012 at 11:27 am

    On Sat, Feb 18, 2012 at 7:26 AM, Soichi Ishida wrote:

    Rails 3.1.3

    I am not sure Rails can do what I want to do.

    I have a form for update like,

    <%= form_for script, :remote => true do |f| %>
    <%= f.hidden_field :video_id %>
    <%= f.text_field :startp, :readonly => true %>
    <%= f.text_field :text %>
    <%= f.submit "update" %>
    <% end %>

    then, JavaScript (jQuery) inserts a value for 'startp' and for 'text' in
    to the 'text_field' .
    Of course, this set of values is already stored in DB. I want to update
    it after editing it.

    This form gives an error

    undefined method `model_name' for NilClass:Class

    whose I assume the cause is the nil object 'Script'. The object is not
    properly passed.

    I try to render this form like following.

    <%= render :partial => "update_script",:locals => { :script =>
    Script.find_by_startp(params[:startp])} %>

    Since 'startp' is readonly and users should be able to edit only 'text',
    I hoped to associate the 'text' with 'startp' rather than 'id' of
    'script'.

    Is there anyway to pass the obejct?
    In the "edit" controller, could you set:

    def edit
    ...
    startp = params[:startp] # or params[:script][:startp] ?
    scripts = Script.find_all_by_startp(startp)
    <process error> unless scripts.size == 1
    @script = scripts.first # should really be '.single'
    ...
    end

    in the view

    <%= render :partial => "update_script",:locals => { :script => @script}
    %>

    HTH (not entirely sure ...),

    Peter


    --
    *** Available for a new project ***

    Peter Vandenabeele
    http://twitter.com/peter_v
    http://rails.vandenabeele.com
    http://coderwall.com/peter_v

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Soichi Ishida at Feb 19, 2012 at 1:56 am
    Thanks for your answer, although it does not quite work well.

    The problem is that

    ':startp'

    is defined in _new_script.html.erb, where a new (script) text along with
    startp are defined.

    <%= form_for script, :remote => true do |f| %>
    <%= f.hidden_field :video_id %>
    <%= f.text_field :startp, :readonly => true %> <=HERE!!!
    <%= f.text_field :text %>
    <%= f.submit "save" %>
    <% end %>


    If there is a way to grasp it somehow in the controller and pass it to
    update action, it seems fine.

    Any idea?

    soichi

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Nelson K. at Feb 19, 2012 at 9:27 am
    <%= form_for script, :remote => true do |f| %>
    Is 'script' in form_for above a local variable or a class? form_for
    normally posts or puts to a class. It doesn't look right to me.

    <%= form_for @script, :remote => true do |f| %>
    or
    <%= form_for :script, url: edit_script_path(), remote: true do |f| %>


    hope it helps

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 18, '12 at 6:26a
activeFeb 19, '12 at 9:27a
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Nelson K.: 3 posts Peter Vandenabeele: 1 post

People

Translate

site design / logo © 2021 Grokbase