Note that there are some explanatory texts on larger screens.

plurals
  1. POModify strings in Rails?
    primarykey
    data
    text
    <p>So I'm new to Rails (teaching myself as a senior project in high school), and I'm trying to figure out how to modify these strings.</p> <p>Let's say someone writes the following string in a form: "you know you are a geek when"</p> <p>How can I automatically change it to this: "You know you are a geek when..."?</p> <p>I need Rails to check the case of the first letter and check for the three dots then modify the string as necessary. I've looked <a href="http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html" rel="nofollow noreferrer" title="here">here</a>, but I can't find anything that would work. </p> <p>Thanks a lot!</p> <p><strong>EDIT:</strong> I'm trying to implement what Reuben Mallaby suggested, but I'm having trouble. Here's the relevant part of the lists_controller.rb file, and below that is the method in the list.rb model.</p> <pre><code>def update @list = List.find(params[:id]) @list.fixlistname respond_to do |format| if @list.update_attributes(params[:list]) flash[:notice] = 'List was successfully updated.' format.html { redirect_to(@list) } format.xml { head :ok } else format.html { render :action =&gt; "edit" } format.xml { render :xml =&gt; @list.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <p>and..</p> <pre><code>def fixlistname new_title = title.humanize + (title.ends_with("...") ? "" : "...") end </code></pre> <p><strong>EDIT 2:</strong> I want the string to be modified before it goes into the database, and this is the error message I'm getting:</p> <blockquote> <p>undefined method `ends_with' for "You know you are a track runner when":String</p> </blockquote> <p><strong>GOT IT WORKING! THANKS EVERYONE!</strong> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload